2
from datetime import datetime
4
from xml.dom.minidom import parse, parseString
6
class scheduler_check_landefeld(osv.osv):
7
_name = 'scheduler.cpi_be'
9
def import_cpi_be_all(self, cr, uid, ids=False, context=None):
10
u1=urllib2.urlopen('http://ng3.economie.fgov.be/ni/indicators/XML/ConsumerPriceIndices.xml')
13
cpi_be_entry_pool = self.pool.get("cpi.be.entry")
14
cpi_be_type_pool = self.pool.get("cpi.be.type")
17
for node_type in dom.childNodes[0].childNodes:
18
if node_type.nodeType == node_type.ELEMENT_NODE and node_type.nodeName == 'INDEX':
25
#BROWSE TYPE AND FIND IT (OR CREATE IT IF NOT EXIST)
26
type_name = node_type.getAttribute("BASE")
27
type_description = node_type.getAttribute("DESCRIPTION")
28
type_ids = cpi_be_type_pool.search(cr, uid, [('name','=',type_name)], context=context)
30
type_id = cpi_be_type_pool.create(cr, uid, {'name':type_name, 'description':type_description}, context=context)
35
for node_year in node_type.childNodes:
36
if node_year.nodeType == node_year.ELEMENT_NODE and node_year.nodeName == 'YEAR':
37
year = int(node_year.getAttribute("NAME"))
38
for values_node in node_year.childNodes:
39
if values_node.nodeType == values_node.ELEMENT_NODE and values_node.nodeName == 'VALUES':
41
for entry_node in values_node.childNodes:
42
if entry_node.nodeType == entry_node.ELEMENT_NODE and entry_node.nodeName == 'ENTRY':
43
month = entry_node.getAttribute("MONTH")
44
if entry_node.childNodes and entry_node.childNodes[0].nodeType == entry_node.childNodes[0].TEXT_NODE:
45
value = float(entry_node.childNodes[0].data)
47
#CREATE OR UPDATE ENTRY
48
if type_id and year and month and value:
49
entries = cpi_be_entry_pool.search(cr, uid, [('type_id','=',type_id),('year','=',year),('month','=',month)], context=context)
51
cpi_be_entry_pool.write(cr, uid, entries, {'value':value}, context=context)
53
cpi_be_entry_pool.create(cr, uid, {'type_id':type_id, 'year':year, 'month':month, 'value':value}, context=context)
58
scheduler_check_landefeld()
b'\\ No newline at end of file'