Mercurial > eagle-eye
changeset 165:4f06f72365fa
merged again
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 02 Nov 2008 00:31:03 +0800 |
parents | 278bd36708e8 (current diff) e49137521123 (diff) |
children | f7fd2738b9b4 |
files | |
diffstat | 2 files changed, 21 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/pyikriam/__init__.py Sun Nov 02 00:30:38 2008 +0800 +++ b/pyikriam/__init__.py Sun Nov 02 00:31:03 2008 +0800 @@ -85,15 +85,20 @@ from lxml import etree from StringIO import StringIO - print "pull datas of the city %s" % self.id - xpath_globalinfo = "/html/body[@id='city']/div[@id='container']/div[@id='container2']" - page = c(self.core.baseurl).get(self.params).get_content() parser = etree.HTMLParser(encoding='utf8') page_dom = etree.parse(StringIO(page), parser) + + xpath_globalinfo = "/html/body[@id='city']/div[@id='container']/div[@id='container2']" for name, path in self.data_patterns.items(): xpath = xpath_globalinfo + path value = page_dom.xpath(xpath)[0] setattr(self, name, value) + pass + + xpath_mainview = '/html/body/div/div/div[@id=\'mainview\']/ul/li' + pos_doms = page_dom.xpath(xpath_mainview) + positions = [pos_dom.get('class').split()[-1] for pos_dom in pos_doms] + self.positions = positions pass pass
--- a/pyikriam/example.py Sun Nov 02 00:30:38 2008 +0800 +++ b/pyikriam/example.py Sun Nov 02 00:31:03 2008 +0800 @@ -1,8 +1,19 @@ +import sys from __init__ import Ikariam +if len(sys.argv) != 2: + print >> sys.stderr, 'Usage: %s <city id>' % (sys.argv[0]) + sys.exit(1) + pass + +city_id = int(sys.argv[1]) # 117261 + i = Ikariam() -city = i.city(117261) +city = i.city(city_id) + +print "pull datas of the city %s" % (city_id) city.sync() + print 'gold is ' + city.gold print 'inhabitants is ' + city.inhabitants print 'wood is ' + city.wood @@ -10,5 +21,5 @@ print 'marble is ' + city.marble print 'crystal is ' + city.crystal print 'sulfur is ' + city.sulfur +print 'positions ' + repr(city.positions) -