Proyecto completo con configuracion de variables de entorno para EasyPanel
This commit is contained in:
58
backend/diag_webform.py
Normal file
58
backend/diag_webform.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# diag_webform.py — Compara WEB_FORMULARIO enero: datos_unificados vs cartera_junta (local xlsx).
|
||||
# Usa el export local para cartera (rapido) y baja solo enero de datos_unificados.
|
||||
import os, requests
|
||||
from datetime import datetime
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
SUP_URL = os.getenv("SUPABASE_URL"); SUP_KEY = os.getenv("SUPABASE_KEY")
|
||||
|
||||
def _norm_tel(v):
|
||||
s = str(v or "")
|
||||
for x in ("+51","+"," ","-","(",")"): s=s.replace(x,"")
|
||||
s=s.strip()
|
||||
if not s or set(s)=={"0"}: return ""
|
||||
if s.isdigit() and len(s)<=6: return ""
|
||||
return s
|
||||
|
||||
def _ene(v):
|
||||
for fmt in ("%d/%m/%Y","%Y-%m-%d"):
|
||||
try:
|
||||
d=datetime.strptime(str(v)[:10],fmt).date()
|
||||
return d.year==2026 and d.month==1
|
||||
except: pass
|
||||
return False
|
||||
|
||||
# datos_unificados WEB_FORMULARIO enero
|
||||
h={"apikey":SUP_KEY,"Authorization":f"Bearer {SUP_KEY}"}
|
||||
out=[]; desde=0
|
||||
while True:
|
||||
r=requests.get(f"{SUP_URL}/rest/v1/datos_unificados",
|
||||
params={"select":"Telefono,Canal,Fechacreada","offset":str(desde),"limit":"1000"},headers=h,timeout=60)
|
||||
r.raise_for_status(); d=r.json()
|
||||
if not d: break
|
||||
out.extend(d)
|
||||
if len(d)<1000: break
|
||||
desde+=1000
|
||||
du=[_norm_tel(r["Telefono"]) for r in out if str(r.get("Canal","")).upper()=="WEB_FORMULARIO" and _ene(r.get("Fechacreada"))]
|
||||
du=set(t for t in du if t)
|
||||
print("datos_unificados WEB_FORMULARIO enero (tel unicos):", len(du))
|
||||
|
||||
# cartera desde el excel local
|
||||
import openpyxl, glob
|
||||
xf=max(glob.glob("cartera_junta_export.xlsx"), default=None)
|
||||
wb=openpyxl.load_workbook("cartera_junta_export.xlsx", read_only=True); ws=wb.active
|
||||
rows=list(ws.iter_rows(values_only=True)); hdr=rows[0]; ci={h:i for i,h in enumerate(hdr)}
|
||||
tel_all=set(str(r[ci["telefono"]]).strip() for r in rows[1:]) # todos los tel de cartera
|
||||
tel_web_ene=set()
|
||||
for r in rows[1:]:
|
||||
if str(r[ci["canal"]]).strip().upper()=="WEB_FORMULARIO" and str(r[ci["fecha_creada"]])[:7]=="2026-01":
|
||||
tel_web_ene.add(str(r[ci["telefono"]]).strip())
|
||||
print("cartera WEB_FORMULARIO enero (tel):", len(tel_web_ene))
|
||||
|
||||
falt_total=[t for t in du if t not in tel_all]
|
||||
falt_web=[t for t in du if t not in tel_web_ene]
|
||||
print(f"\nDe {len(du)} tel de datos_unificados enero:")
|
||||
print(f" NO estan en cartera por NINGUN canal: {len(falt_total)}")
|
||||
print(f" estan en cartera pero NO como WEB_FORMULARIO enero: {len(falt_web)-len(falt_total)}")
|
||||
print(" ejemplos NO en cartera:", falt_total[:10])
|
||||
Reference in New Issue
Block a user