01ea6d90bdfcbf835fb46c025ad238433884eaa1
2 # -*- coding: utf-8 -*-
7 db_name
= "heureuxcyclage"
14 conn
= psycopg2
.connect("dbname=%s user=%s host=%s" % (db_name
, db_user
, db_host
))
17 # import datas in dicos
18 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"
21 root
= etree
.Element('directory')
22 group
= etree
.SubElement(root
, 'DIR_GROUP')
33 fields
['NUMBER_WORK'] = unicode(str(row
[1]), 'utf-8')
35 fields
['NUMBER_MOBILE'] = unicode(str(row
[2]), 'utf-8')
37 fields
['NAME_LAST'] = unicode(row
[0], 'utf-8')
39 name
= unicode(row
[0], 'utf-8')
41 pspace
= name
.index(' ')
42 fields
['NAME_FIRST'] = name
[:pspace
]
43 fields
['NAME_LAST'] = name
[pspace
+1:]
45 fields
['NAME_FIRST'] = name
47 entry
= etree
.SubElement(group
, 'DIR_ENTRY')
50 entry_field
= etree
.SubElement(entry
, 'DIR_ENTRY_%s' % field
.upper())
51 entry_field
.text
= fields
[field
]
61 content
= '<?xml version="1.0"?>\n%s' % etree
.tostring(root
, pretty_print
=True)