+clear unused characters in phone numbers
[lhc/oe_alcatel_export.git] / alcatel_export.py
index 01ea6d9..727d806 100644 (file)
@@ -9,13 +9,18 @@ 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))
 cur = conn.cursor()
 
 # import datas in dicos
-query = "SELECT name, phone, mobile, is_company from res_partner where name != '/' and name is not null and (phone is not null or mobile is not null) and active = True and is_company = True"
+query = "SELECT name, phone, mobile, is_company from res_partner where name != '/' and name is not null and (phone is not null or mobile is not null) and active = True and usual_contact = True"
 cur.execute(query)
 
 root = etree.Element('directory')
@@ -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: