From: Ludovic CHEVALIER Date: Wed, 8 Mar 2017 10:46:12 +0000 (+0100) Subject: +clear unused characters in phone numbers X-Git-Url: http://git.cyclocoop.org/?p=lhc%2Foe_alcatel_export.git;a=commitdiff_plain;h=29b338a5661e85975723f960fc316051834f44e9 +clear unused characters in phone numbers --- diff --git a/alcatel_export.py b/alcatel_export.py index bff9c92..727d806 100644 --- a/alcatel_export.py +++ b/alcatel_export.py @@ -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: