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

28 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
import sys,json,subprocess
def run(c):
try: return subprocess.run(c,shell=True,capture_output=True,text=True,timeout=30).stdout.strip()
except: return ""
def api(a):
import urllib.request
try:
r=urllib.request.urlopen(f"https://weval-consulting.com/api/ethica-api.php?action={a}&token=ETHICA_API_2026_SECURE",timeout=10)
return json.loads(r.read())
except: return {}
def status():
d=api("dashboard");cs=api("consent_stats")
gap=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),"gap":gap,"consents":len(cs.get("consent_stats",[]))}))
def enrichment():
s=api("stats")
gaps=[x 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":gaps}))
def fix_logs():
for l in["ethica-enrich-v4","ethica-enrich-searxng","ethica-autonomous","ethica-opens"]:
run(f"touch /var/log/{l}.log; chmod 666 /var/log/{l}.log")
print("{\"fixed\":true}")
if __name__=="__main__":
a=sys.argv[1] if len(sys.argv)>1 else "status"
{"status":status,"enrichment":enrichment,"fix-logs":fix_logs}.get(a,lambda:print(f"{{\"error\":\"{a}\"}}"))()