comparison pyikriam/sync_utils.py @ 188:bf4ddf5bffb9

Extracts information about resources required to upgrade a building.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 02 Nov 2008 22:31:06 +0800
parents 6adad3bcca78
children 015ac84d038c
comparison
equal deleted inserted replaced
178:bff16e6ee3ef 188:bf4ddf5bffb9
1 ## \file 1 ## \file
2 # \brief Sync information of objects with DOM trees of respective pages. 2 # \brief Sync information of objects with DOM trees of respective pages.
3 # 3 #
4
5 import re as _re
4 6
5 def sync_tagclass(obj, patterns, page_dom): 7 def sync_tagclass(obj, patterns, page_dom):
6 xpath_building = '/html/body/descendant::*[@class=\'%s\']/text()' 8 xpath_building = '/html/body/descendant::*[@class=\'%s\']/text()'
7 for name, clzname in patterns.items(): 9 for name, clzname in patterns.items():
8 path = xpath_building % (clzname) 10 path = xpath_building % (clzname)
40 setattr(obj, name, False) 42 setattr(obj, name, False)
41 pass 43 pass
42 pass 44 pass
43 pass 45 pass
44 46
47 _reo_tv = _re.compile(u'(([0-9]+)\u6642)? ?(([0-9]+)\u5206)? ?(([0-9]+)\u79d2)?')
48 ## \brief Translate timeval in Chinese text format to integer seconds.
49 #
50 def ikariam_zh_timeval(tv_str):
51 tmo = _reo_tv.match(tv_str)
52 if not tmo:
53 raise SyntaxError, \
54 '%s is an invalid time interval string' % (repr(tv_str))
55 tv = 0
56
57 value = tmo.group(2) # hour
58 if value:
59 tv = tv + int(value) * 360
60 pass
61
62 value = tmo.group(4) # minute
63 if value:
64 tv = tv + int(value) * 60
65 pass
66
67 value = tmo.group(6) # second
68 if value:
69 tv = tv + int(value)
70 pass
71
72 return tv