Skip to content

Commit 92c265f

Browse files
clean (), unicode and 0 after international prefix in phone
1 parent 16c84ec commit 92c265f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

group_opendata_by_station.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#!/usr/bin/env python
23
# coding: utf-8
34

@@ -46,7 +47,16 @@ def is_correct_id(station_id):
4647
def cleanPhoneNumber(phone):
4748
if phone.startswith("tel:"):
4849
phone = phone[4:]
49-
phone = phone.replace(" ", "").replace("-", "").replace(".", "")
50+
# Suppression des caractères de contrôle Unicode
51+
phone = re.sub(r'[\u2000-\u206F]', '', phone)
52+
# Suppression de tous les séparateurs
53+
phone = phone.replace(" ", "").replace("-", "").replace(".", "").replace("(", "").replace(")", "")
54+
# Suppression du 0 après +33 ou 33
55+
if phone.startswith("+330"):
56+
phone = "+33" + phone[4:]
57+
if phone.startswith("330"):
58+
phone = "+33" + phone[3:]
59+
# Tests sur le numéro nettoyé
5060
if re.match(r"^\+33\d{9}$", phone):
5161
return phone
5262
elif re.match(r"^33\d{9}$", phone):

0 commit comments

Comments
 (0)