comparison pyikriam/sync_utils.py @ 177:6adad3bcca78

Refactory to functions for sychronizing object attributes with pages. - We add more building types. - All of them need to sync attributes with content of Ikariam's online page. - These functions are refactoried to functions.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 02 Nov 2008 15:14:51 +0800
parents
children bf4ddf5bffb9
comparison
equal deleted inserted replaced
176:3ba3edda6d1e 177:6adad3bcca78
1 ## \file
2 # \brief Sync information of objects with DOM trees of respective pages.
3 #
4
5 def sync_tagclass(obj, patterns, page_dom):
6 xpath_building = '/html/body/descendant::*[@class=\'%s\']/text()'
7 for name, clzname in patterns.items():
8 path = xpath_building % (clzname)
9 value = float(page_dom.xpath(path)[0])
10 setattr(obj, name, value)
11 pass
12 pass
13
14 def sync_tagvalue(obj, patterns, page_dom):
15 xpath_value = '/html/body/descendant::*[starts-with(@class,\'%s\')]/descendant::*[@class=\'value\']/text()'
16 for name, clzname in patterns.items():
17 path = xpath_value % (clzname)
18 value = float(page_dom.xpath(path)[0])
19 setattr(obj, name, value)
20 pass
21 pass
22
23 def sync_tagcount(obj, patterns, page_dom):
24 xpath_count = '/html/body/descendant::*[starts-with(@class,\'%s\')]/descendant::*[@class=\'count\']/text()'
25 for name, clzname in patterns.items():
26 path = xpath_count % (clzname)
27 value = int(page_dom.xpath(path)[0])
28 setattr(obj, name, value)
29 pass
30 pass
31
32 def sync_tagclass_start_appear(obj, patterns, page_dom):
33 xpath_appear = '/html/body/descendant::*[starts-with(@class,\'%s\')]'
34 for name, clzname in patterns.items():
35 path = xpath_appear % (clzname)
36 cnt = len(page_dom.xpath(path))
37 if cnt != 0:
38 setattr(obj, name, True)
39 else:
40 setattr(obj, name, False)
41 pass
42 pass
43 pass
44