fill_emails: fallback prenom.nom@sanef.com si pas de match contact

This commit is contained in:
Pierre & Lumière 2026-04-14 20:46:42 +02:00
parent 7f7b04e775
commit 1ce72a8757

View File

@ -23,6 +23,28 @@ def normalize(s):
return " ".join(ascii_str.split()) return " ".join(ascii_str.split())
def synth_email(name):
"""Genere prenom.nom@sanef.com a partir d'un nom complet.
'Frédéric GRAFFAGNINO' -> 'frederic.graffagnino@sanef.com'
'Pierre-Louis THOUVENOT' -> 'pierre-louis.thouvenot@sanef.com'
"""
if not name:
return None
norm = normalize(name)
parts = [p for p in norm.split() if p]
if len(parts) < 2:
return None
first = parts[0]
last = parts[-1]
# Nettoie caracteres parasites (garde lettres + tiret + apostrophe)
import re
first = re.sub(r"[^a-z\-']", "", first)
last = re.sub(r"[^a-z\-']", "", last)
if not first or not last:
return None
return f"{first}.{last}@sanef.com"
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--dry-run", action="store_true") parser.add_argument("--dry-run", action="store_true")
@ -52,7 +74,7 @@ def main():
print(f"[INFO] {len(rows)} (dom,env) a completer") print(f"[INFO] {len(rows)} (dom,env) a completer")
updated = 0 updated = 0
unmatched = set() from_contacts = synth = 0
for r in rows: for r in rows:
updates = {} updates = {}
if r.responsable_nom and not (r.responsable_email or "").strip(): if r.responsable_nom and not (r.responsable_email or "").strip():
@ -60,15 +82,23 @@ def main():
email = name_to_email.get(key) email = name_to_email.get(key)
if email: if email:
updates["responsable_email"] = email updates["responsable_email"] = email
elif key: from_contacts += 1
unmatched.add(r.responsable_nom) else:
synth_e = synth_email(r.responsable_nom)
if synth_e:
updates["responsable_email"] = synth_e
synth += 1
if r.referent_nom and not (r.referent_email or "").strip(): if r.referent_nom and not (r.referent_email or "").strip():
key = normalize(r.referent_nom) key = normalize(r.referent_nom)
email = name_to_email.get(key) email = name_to_email.get(key)
if email: if email:
updates["referent_email"] = email updates["referent_email"] = email
elif key: from_contacts += 1
unmatched.add(r.referent_nom) else:
synth_e = synth_email(r.referent_nom)
if synth_e:
updates["referent_email"] = synth_e
synth += 1
if not updates: if not updates:
continue continue
@ -81,10 +111,8 @@ def main():
updated += 1 updated += 1
conn.close() conn.close()
print(f"\n[DONE] Maj: {updated}") print(f"\n[DONE] Maj: {updated} | depuis contacts: {from_contacts} | "
if unmatched: f"synthetises (prenom.nom@sanef.com): {synth}")
print(f"[WARN] Noms sans match dans contacts ({len(unmatched)}) : "
f"{sorted(unmatched)[:10]}...")
if __name__ == "__main__": if __name__ == "__main__":