Skip to content

Commit

Permalink
public_services_FR - fix opening_hours & phone
Browse files Browse the repository at this point in the history
  • Loading branch information
nlehuby committed Nov 24, 2023
1 parent 18c54db commit 0acb4fc
Showing 1 changed file with 51 additions and 15 deletions.
66 changes: 51 additions & 15 deletions analysers/analyser_merge_public_services_FR.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ def fetch(self, url, tmp_file, date_string=None):
elem["name"] = None
elem["contact:phone"] = None
if feature.get("telephone"):
phone_number = feature["telephone"][0]["valeur"]
if len(phone_number) > 9 and phone_number.startswith("0") and '(' not in phone_number:
elem["contact:phone"] = "+33 " + phone_number[1:]
elem["contact:phone"] = retreat_phone_number(feature["code_insee_commune"], feature["telephone"][0]["valeur"])
elem["contact:website"] = None
if feature.get("site_internet"):
elem["contact:website"] = feature.get("site_internet")[0]["valeur"]
Expand Down Expand Up @@ -274,6 +272,10 @@ def parse_opening_hours(txt):

opening_hours = ""
for plage in txt:
if not plage["nom_jour_fin"] or not plage["nom_jour_debut"]:
return
if not plage["valeur_heure_debut_1"] or not plage["valeur_heure_fin_1"]:
return
opening_hours += osm_days[plage["nom_jour_debut"]]
if plage["nom_jour_debut"] != plage["nom_jour_fin"]:
opening_hours += "-{}".format(osm_days[plage["nom_jour_fin"]])
Expand All @@ -287,34 +289,37 @@ def parse_opening_hours(txt):

def _retreat_name(official_name):
zz = official_name.split(" - ")
if len(zz) == 1:
if len(zz) != 2:
return
city_name = zz[1]

if city_name.startswith("A"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("E"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("I"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("O"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("U"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("É"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("È"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("Ê"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("Î"):
return
return official_name.replace(" - ", " d'")
if city_name.startswith("Le "):
return
return official_name.replace(" - Le ", " du ")
if city_name.startswith("Les "):
return
return official_name.replace(" - Les ", " des ")
if city_name.startswith("H"):
return official_name.replace(" - ", " d'")
return official_name.replace(" - ", " de ")


def retreat_sous_prefecture_name(official_name):
name = _retreat_name(official_name)
if name:
Expand Down Expand Up @@ -354,3 +359,34 @@ def retreat_Urssaf_name(official_name):
if not official_name.startswith("Urssaf"):
return
return official_name.split(" - ")[0]

def retreat_phone_number(insee, phone_number):
if len(phone_number) < 9:
return
if '(' in phone_number:
return
if not phone_number.startswith("0"):
return
if insee.startswith("971"):
return "+590 " + phone_number[1:]
if insee.startswith("972"):
return "+596 " + phone_number[1:]
if insee.startswith("973"):
return "+594 " + phone_number[1:]
if insee.startswith("974"):
return "+262 " + phone_number[1:]
if insee.startswith("975"):
return "+508 " + phone_number[1:]
if insee.startswith("976"):
return "+262 " + phone_number[1:]
if insee.startswith("977"):
return "+590 " + phone_number[1:]
if insee.startswith("978"):
return "+590 " + phone_number[1:]
if insee.startswith("986"):
return "+681 " + phone_number[1:]
if insee.startswith("987"):
return "+689 " + phone_number[1:]
if insee.startswith("988"):
return "+687 " + phone_number[1:]
return "+33 " + phone_number[1:]

0 comments on commit 0acb4fc

Please sign in to comment.