Mercurial > eagle-eye
annotate 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 |
rev | line source |
---|---|
177
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 ## \file |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 # \brief Sync information of objects with DOM trees of respective pages. |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 # |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 def sync_tagclass(obj, patterns, page_dom): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 xpath_building = '/html/body/descendant::*[@class=\'%s\']/text()' |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 for name, clzname in patterns.items(): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 path = xpath_building % (clzname) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 value = float(page_dom.xpath(path)[0]) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 setattr(obj, name, value) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 def sync_tagvalue(obj, patterns, page_dom): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 xpath_value = '/html/body/descendant::*[starts-with(@class,\'%s\')]/descendant::*[@class=\'value\']/text()' |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 for name, clzname in patterns.items(): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 path = xpath_value % (clzname) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 value = float(page_dom.xpath(path)[0]) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 setattr(obj, name, value) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 def sync_tagcount(obj, patterns, page_dom): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 xpath_count = '/html/body/descendant::*[starts-with(@class,\'%s\')]/descendant::*[@class=\'count\']/text()' |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 for name, clzname in patterns.items(): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 path = xpath_count % (clzname) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 value = int(page_dom.xpath(path)[0]) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 setattr(obj, name, value) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 def sync_tagclass_start_appear(obj, patterns, page_dom): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 xpath_appear = '/html/body/descendant::*[starts-with(@class,\'%s\')]' |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 for name, clzname in patterns.items(): |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 path = xpath_appear % (clzname) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 cnt = len(page_dom.xpath(path)) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 if cnt != 0: |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 setattr(obj, name, True) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 else: |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 setattr(obj, name, False) |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 pass |
6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 |