2 # -*- coding: utf-8 -*-
7 db_name
= "heureuxcyclage"
13 def keep_numbers_only(sentence
):
14 """Return a string with only number characters"""
16 return ''.join(c
for c
in sentence
if c
in set)
19 conn
= psycopg2
.connect("dbname=%s user=%s host=%s" % (db_name
, db_user
, db_host
))
22 # import datas in dicos
23 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"
26 root
= etree
.Element('directory')
27 group
= etree
.SubElement(root
, 'DIR_GROUP')
38 fields
['NUMBER_WORK'] = keep_numbers_only(unicode(str(row
[1]), 'utf-8'))
40 fields
['NUMBER_MOBILE'] = keep_numbers_only(unicode(str(row
[2]), 'utf-8'))
42 fields
['NAME_LAST'] = unicode(row
[0], 'utf-8')
44 name
= unicode(row
[0], 'utf-8')
46 pspace
= name
.index(' ')
47 fields
['NAME_FIRST'] = name
[:pspace
]
48 fields
['NAME_LAST'] = name
[pspace
+1:]
50 fields
['NAME_FIRST'] = name
52 entry
= etree
.SubElement(group
, 'DIR_ENTRY')
55 entry_field
= etree
.SubElement(entry
, 'DIR_ENTRY_%s' % field
.upper())
56 entry_field
.text
= fields
[field
]
66 content
= '<?xml version="1.0"?>\n%s' % etree
.tostring(root
, pretty_print
=True)