Mercurial > eagle-eye
view pyikriam/sync_utils.py @ 187:fa34cdb6879a
merged.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 02 Nov 2008 21:19:07 +0800 |
parents | 6adad3bcca78 |
children | bf4ddf5bffb9 |
line wrap: on
line source
## \file # \brief Sync information of objects with DOM trees of respective pages. # def sync_tagclass(obj, patterns, page_dom): xpath_building = '/html/body/descendant::*[@class=\'%s\']/text()' for name, clzname in patterns.items(): path = xpath_building % (clzname) value = float(page_dom.xpath(path)[0]) setattr(obj, name, value) pass pass def sync_tagvalue(obj, patterns, page_dom): xpath_value = '/html/body/descendant::*[starts-with(@class,\'%s\')]/descendant::*[@class=\'value\']/text()' for name, clzname in patterns.items(): path = xpath_value % (clzname) value = float(page_dom.xpath(path)[0]) setattr(obj, name, value) pass pass def sync_tagcount(obj, patterns, page_dom): xpath_count = '/html/body/descendant::*[starts-with(@class,\'%s\')]/descendant::*[@class=\'count\']/text()' for name, clzname in patterns.items(): path = xpath_count % (clzname) value = int(page_dom.xpath(path)[0]) setattr(obj, name, value) pass pass def sync_tagclass_start_appear(obj, patterns, page_dom): xpath_appear = '/html/body/descendant::*[starts-with(@class,\'%s\')]' for name, clzname in patterns.items(): path = xpath_appear % (clzname) cnt = len(page_dom.xpath(path)) if cnt != 0: setattr(obj, name, True) else: setattr(obj, name, False) pass pass pass