Files
weval-l99/ecm.py
2026-04-15 01:38:46 +02:00

39 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
import sys,json,urllib.request,ssl
T="ETHICA_API_2026_SECURE"
ctx=ssl.create_default_context()
ctx.check_hostname=False
ctx.verify_mode=ssl.CERT_NONE
def api(a,extra=""):
url=f"https://127.0.0.1/api/ethica-api.php?action={a}&token={T}{extra}"
req=urllib.request.Request(url,headers={"Host":"weval-consulting.com"})
try: return json.loads(urllib.request.urlopen(req,timeout=10,context=ctx).read())
except Exception as e: return {"error":str(e)}
def status():
d=api("dashboard");cs=api("consent_stats")
g=d.get("total_hcp",0)-d.get("with_email",0)
print(json.dumps({"total":d.get("total_hcp",0),"emails":d.get("with_email",0),"phones":d.get("with_telephone",0),"gap":g,"consents":len(cs.get("consent_stats",[])),"pipeline":d.get("pipeline","?")}))
def enrichment():
s=api("stats")
lo=[x["source"] for x in s.get("by_source",[]) if float(x.get("couverture","100"))<50]
print(json.dumps({"gap":s.get("total",0)-s.get("with_email",0),"pending":s.get("enrichment_pending",0),"low_sources":lo}))
def pilot():
data=api("search","&pays=DZ&specialite=generaliste&limit=500")
contacts=data.get("data",[])
ok=[c for c in contacts if c.get("email") and c.get("consent_status") is None]
print(json.dumps({"pilot_ready":len(ok)>0,"total_dz_mg":data.get("total",0),"with_email_no_consent":len(ok),"sample":[{"nom":c["nom"],"prenom":c.get("prenom",""),"email":c["email"]} for c in ok[:3]],"mode":"DRY_RUN"}))
def readiness():
d=api("dashboard");cs=api("consent_stats");s=api("stats")
blockers=[]
if len(cs.get("consent_stats",[]))==0: blockers.append("0_consents")
gap=d.get("total_hcp",0)-d.get("with_email",0)
if gap>15000: blockers.append(f"email_gap_{gap}")
by_c=s.get("by_country",[])
for c in by_c:
if c["pays"]=="MA" and int(c.get("email",0))<15000: blockers.append("MA_low_77pct")
print(json.dumps({"ready":len(blockers)==0,"blockers":blockers,"total":d.get("total_hcp",0),"emails":d.get("with_email",0)}))
if __name__=="__main__":
a=sys.argv[1] if len(sys.argv)>1 else "status"
{"status":status,"enrichment":enrichment,"pilot":pilot,"readiness":readiness}.get(a,lambda:print("unknown"))()