Compare commits

..

No commits in common. "e7aef5a40462fcd745a505adcf4500d89f747653" and "4c289b4aae7a84b65d1e68c9d20bfaafa2e1b7d7" have entirely different histories.

3 changed files with 3728 additions and 5378 deletions

View File

@ -1,147 +0,0 @@
import sqlite3
import os
from rich.console import Console
from rich.table import Table
from rich import box
selfpath = os.path.abspath(os.path.dirname(__file__))
console = Console()
conn = sqlite3.connect(f'{selfpath}/../ipinfo.db')
c = conn.cursor()
# Detalle Visitas por pais
def vistas_pais_detalle(pais):
pais = pais
consulta = f"""
SELECT DATE(fecha, 'unixepoch') AS fecha_local, ip, metodo, cod_html, consulta
FROM visita WHERE ip IN (SELECT `ip` FROM `registro` WHERE `pais` = '{pais}');
"""
c.execute(consulta)
resp = c.fetchall()
return resp
def pt_visita_pais_detalle(pais):
respuesta = vistas_pais_detalle(pais)
tbl_v = Table(
title=f"[bold][blue]Detalle visitas pais: [/blue][yellow]{pais}[/yellow][/bold]",
box = box.ROUNDED,
show_lines = False,
row_styles=["dim", ""],
border_style="dark_magenta")
tbl_v.add_column("Fecha", justify="center", style="bright_yellow")
tbl_v.add_column("IP", justify="left", style="bright_cyan")
tbl_v.add_column("Metodo", justify="left", style="bright_green")
tbl_v.add_column("Respuesta", justify="left", style="bright_blue")
tbl_v.add_column("Consulta", justify="left", style="yellow")
for item in respuesta:
tbl_v.add_row(str(item[0]), str(item[1]), str(item[2]), str(item[3]), str(item[4]))
console.print(tbl_v)
# Formato fecha -- Convertir fecha 'unixepoch' a 'localtime'
def unix_to_local_date():
consulta = """
SELECT DATE(fecha, 'unixepoch') AS fecha_local FROM visita;
"""
c.execute(consulta)
return c.fetchall()
# Select cod 200 -- SELECT all from registro where ip=(SELECT ip from visita where cod_html=200);
def select_cod(codigo):
consulta = f"""
SELECT geoloc FROM registro WHERE ip IN
(SELECT ip FROM visita WHERE cod_html = {codigo});
"""
c.execute(consulta)
resp = c.fetchall()
return resp
# Select fecha mayor que (ej. 1661226920)
def sel_pais_desde(pais, unix_e):
consulta = f"""
SELECT DATE(fecha, 'unixepoch') AS fecha_local, ip, metodo, cod_html, consulta
FROM visita WHERE ip IN (SELECT `ip` FROM `registro` WHERE `pais` = '{pais}') and fecha > {unix_e};
"""
c.execute(consulta)
resp = c.fetchall()
return resp
def pt_sel_pais_fecha(pais, unix_e):
respuesta = sel_pais_desde(pais, unix_e)
tbl_v = Table(
title=f"[bold][blue]Visitas {pais}, desde {unix_e}[/blue][/bold]",
box = box.ROUNDED,
show_lines = False,
row_styles=["dim", ""],
border_style="dark_magenta")
tbl_v.add_column("Fecha", justify="center", style="bright_yellow")
tbl_v.add_column("IP", justify="left", style="bright_cyan")
tbl_v.add_column("Metodo", justify="left", style="bright_green")
tbl_v.add_column("Respuesta", justify="left", style="bright_blue")
tbl_v.add_column("Consulta", justify="left", style="yellow")
for item in respuesta:
tbl_v.add_row(str(item[0]), str(item[1]), str(item[2]), str(item[3]), str(item[4]))
console.print(tbl_v)
# Top 50 paises
def top_paises(top):
consulta = f"""
SELECT pais,
count(pais) AS Ocurrencias
FROM registro
GROUP BY pais
ORDER BY count(*) DESC
LIMIT {top};
"""
c.execute(consulta)
resp = c.fetchall()
return resp
def pt_top_paises(top):
respuesta = top_paises(top)
tbl_v = Table(
title=f"[bold][blue]Vistas Top {top}[/blue][/bold]",
box = box.ROUNDED,
show_lines = False,
row_styles=["dim", ""],
border_style="dark_magenta")
tbl_v.add_column("País", justify="center", style="bright_yellow")
tbl_v.add_column("Visitas", justify="left", style="bright_cyan")
for item in respuesta:
tbl_v.add_row(str(item[0]), str(item[1]))
console.print(tbl_v)
# respuesta HTML para pais=?
def cod_html_pais(pais):
consulta = f"""
SELECT cod_html,
count(cod_html) AS Ocurrencias
FROM visita
WHERE ip IN (SELECT `ip` FROM `registro` WHERE `pais` = '{pais}')
GROUP BY cod_html
ORDER BY count(*) DESC;
"""
c.execute(consulta)
resp = c.fetchall()
return resp
def pt_html_cod_pais(pais):
respuesta = cod_html_pais(pais)
tbl_v = Table(
title=f"[bold][blue]Códigos html: [/blue][green]{pais}[/bold][/green]",
box = box.ROUNDED,
show_lines = False,
row_styles=["dim", ""],
border_style="dark_magenta")
tbl_v.add_column("Código", justify="center", style="bright_yellow")
tbl_v.add_column("Conteo", justify="left", style="bright_cyan")
for item in respuesta:
tbl_v.add_row(str(item[0]), str(item[1]))
console.print(tbl_v)

View File

@ -11,7 +11,6 @@ import sql_alch
from rich import box
from rich.console import Console
from rich.table import Table
import consultas.querys_sqlite as querys
selfpath = os.path.abspath(os.path.dirname(__file__))
ownip = requests.get('https://ifconfig.me/').text
@ -219,23 +218,6 @@ def main():
case '-M':
console.print('[bold yellow]Generando mapa de visitas[/bold yellow]')
sql_alch.mapsgen()
case '-q':
match sys.argv[2]:
case '-p':
pais = sys.argv[3]
querys.pt_html_cod_pais(pais.upper())
case '--top':
top = sys.argv[3]
querys.pt_top_paises(top)
case '--pais-desde':
pais = sys.argv[3]
desde = sys.argv[4]
querys.pt_sel_pais_fecha(pais.upper(), desde)
case '--detalle-pais':
pais = sys.argv[3]
querys.pt_visita_pais_detalle(pais.upper())
case _:
console.print(f'[red] query desconocida [bold]{sys.argv[2]}[/bold][/red]')
case _:
ip = sys.argv[1]
print_ipinfo(ip, False)

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 999 KiB