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))
'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: