drop regex usage, updt: requirements & map_thumb

This commit is contained in:
devfzn 2024-02-14 01:02:02 -03:00
parent cd308c60eb
commit d6b7e3ff48
4 changed files with 36 additions and 22 deletions

View File

@ -4,7 +4,6 @@ import os
import sys
import subprocess
import requests
import re
import configparser as cfg
from os.path import isfile
import sql_alch
@ -23,9 +22,6 @@ muevelog = f'{selfpath}/muevelog.sh '
log_file = f'{selfpath}/log/iplocate.log'
console = Console()
# tkn=True
# stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python
ip_regx = "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"
ip_local_regx = "^192\.168\.0\.([0-9]|[0-9][0-9]|[0-9][0-9][0-9])$"
logging.basicConfig(
filename=log_file,
@ -35,6 +31,25 @@ logging.basicConfig(
logging.info("iplocate inicio")
def valid_ip(ip_str):
ip = ip_str.split('.')
if len(ip) != 4:
return False
else:
for segm in ip:
if not segm.isdigit() or not (255 >= int(segm) >= 0):
return False
return True
def local_ip(ip_str):
ip = ip_str.split('.')
if ip[0] == '192' and ip[1] == '168':
return True
else:
return False
def log_usage(proceso, info):
usage_log = f"Proceso:[{proceso}] - Info: [{info}]"
logging.info(usage_log)
@ -52,11 +67,11 @@ except Exception as ex:
def filtro_ip_propia(ip):
return True if ip != ownip and not re.search(ip_local_regx, ip) else False
return True if ip != ownip and not local_ip(ip) else False
def print_ipinfo(ip, tkn=True):
if (re.search(ip_regx, ip)):
if valid_ip(ip):
try:
ip_info = sql_alch.consulta_ip(ip, tkn)
except Exception as ex:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 KiB

After

Width:  |  Height:  |  Size: 278 KiB

View File

@ -1,22 +1,22 @@
appdirs==1.4.4
certifi==2021.10.8
charset-normalizer==2.0.12
certifi==2022.12.7
charset-normalizer==3.1.0
commonmark==0.9.1
future==0.18.2
future==0.18.3
geographiclib==2.0
gpxpy==1.5.0
greenlet==1.1.2
idna==3.3
Pillow==9.1.0
greenlet==2.0.2
idna==3.4
Pillow==9.5.0
py-staticmaps==0.4.0
pycairo==1.21.0
Pygments==2.12.0
pycairo==1.23.0
Pygments==2.15.1
python-slugify==6.1.2
requests==2.27.1
rich==12.4.1
requests==2.30.0
rich==13.3.5
s2sphere==0.2.5
SQLAlchemy==1.4.36
svgwrite==1.4.2
SQLAlchemy==2.0.12
svgwrite==1.4.3
text-unidecode==1.3
textual==0.1.18
urllib3==1.26.9
urllib3==2.0.2

View File

@ -2,7 +2,7 @@ import os
import time
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 requests, token, filtro_ip_propia, selfpath, parser, log_usage, valid_ip
from json import loads
from datetime import datetime
from sqlalchemy import create_engine
@ -16,7 +16,6 @@ from rich.progress import Progress, track
from rich.console import Console
from mapsgen import maps_gen
ip_regx = "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"
logs_dir = parser.get('bash_script', 'destino_log')
logs_dir = logs_dir.strip("'")
base_de_datos = f'sqlite:////{selfpath}/ipinfo.db'
@ -406,7 +405,7 @@ def consulta_ip(ip_consulta, tkn=True):
"""Consulta API o base de datos por la IPs pasada como argumento,
filtra IPs validas antes de proceder.
"""
if (re.search(ip_regx, ip_consulta)):
if valid_ip(ip_consulta):
match tkn:
case True:
consulta = f'https://ipinfo.io/{ip_consulta}{token}'