+clear unused characters in phone numbers 7.0
authorLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Wed, 8 Mar 2017 10:46:12 +0000 (11:46 +0100)
committerLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Wed, 8 Mar 2017 10:46:12 +0000 (11:46 +0100)
alcatel_export.py

index bff9c92..727d806 100644 (file)
@@ -9,6 +9,11 @@ db_user = "bikecoop"
 db_host = "localhost"
 limit = 0
 
+# functions
+def keep_numbers_only(sentence):
+    """Return a string with only number characters"""
+    set = '0123456789'
+    return ''.join(c for c in sentence if c in set)
 
 # sql connect
 conn = psycopg2.connect("dbname=%s user=%s host=%s" % (db_name, db_user, db_host))
@@ -30,9 +35,9 @@ for row in cur:
         'RINGER': '0',
     }
     if row[1]:
-        fields['NUMBER_WORK'] = unicode(str(row[1]), 'utf-8')
+        fields['NUMBER_WORK'] = keep_numbers_only(unicode(str(row[1]), 'utf-8'))
     if row[2]:
-        fields['NUMBER_MOBILE'] = unicode(str(row[2]), 'utf-8')
+        fields['NUMBER_MOBILE'] = keep_numbers_only(unicode(str(row[2]), 'utf-8'))
     if row[3]:
         fields['NAME_LAST'] = unicode(row[0], 'utf-8')
     else: