fix: query geolocalization pure SQL

deprecating ORM SQLalchemy
This commit is contained in:
devfzn 2023-06-06 04:48:14 -04:00
parent b58964d68f
commit 83f109ee60
4 changed files with 20 additions and 5 deletions

View File

@ -9,6 +9,21 @@ console = Console()
conn = sqlite3.connect(f'{selfpath}/../ipinfo.db') conn = sqlite3.connect(f'{selfpath}/../ipinfo.db')
c = conn.cursor() c = conn.cursor()
# GeoLoc
def get_geoloc(codigo):
if codigo == 200:
consulta = """
SELECT DISTINCT geoloc FROM registro WHERE ip in ( SELECT `ip` from visita WHERE cod_html=='200');
"""
else:
consulta = """
SELECT DISTINCT geoloc FROM registro WHERE ip in ( SELECT `ip` from visita WHERE cod_html!='200');
"""
c.execute(consulta)
resp = c.fetchall()
return resp
# Detalle Visitas por pais # Detalle Visitas por pais
def vistas_pais_detalle(pais, codigo=''): def vistas_pais_detalle(pais, codigo=''):
if codigo == '': if codigo == '':

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 263 KiB

View File

@ -41,6 +41,7 @@ def map300(geolocs):
def maps_gen(locs_200, locs_300): def maps_gen(locs_200, locs_300):
maps_thumbs(locs_200, locs_300)
map200(locs_200) map200(locs_200)
map300(locs_300) map300(locs_300)
for loc in locs_300: for loc in locs_300:

View File

@ -1,6 +1,7 @@
import os import os
import time import time
import subprocess import subprocess
from consultas.querys_sqlite import get_geoloc
from iplocate import re, requests, token, filtro_ip_propia, selfpath, parser, log_usage from iplocate import re, requests, token, filtro_ip_propia, selfpath, parser, log_usage
from json import loads from json import loads
from datetime import datetime from datetime import datetime
@ -468,10 +469,8 @@ def mapsgen():
Llama a función maps_gen con estas listas de valores como argumentos. Llama a función maps_gen con estas listas de valores como argumentos.
""" """
try: try:
stmn = session.query(Registro.geoloc.distinct()).join('visitas').where(Visita.cod_html==200) loc_200 = get_geoloc(200)
loc_200 = session.execute(stmn).all() loc_300 = get_geoloc(300)
stmn = session.query(Registro.geoloc.distinct()).join('visitas').where(Visita.cod_html!=200)
loc_300 = session.execute(stmn).all()
maps_gen(loc_200, loc_300) maps_gen(loc_200, loc_300)
except Exception as ex: except Exception as ex:
print('Exception mapsgen: ', ex) print('Exception mapsgen: ', ex)