# HG changeset patch # User Thinker K.F. Li # Date 1225555973 -28800 # Node ID e49137521123464987b4cdc232a7ffbba2cb6487 # Parent 1507c2d16b35a9b15ee189f4f94b49f476a11c87 pyikriam retrive information about land positions. - It retrive type of building on positions. diff -r 1507c2d16b35 -r e49137521123 pyikriam/__init__.py --- a/pyikriam/__init__.py Sat Nov 01 22:21:25 2008 +0800 +++ b/pyikriam/__init__.py Sun Nov 02 00:12:53 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 diff -r 1507c2d16b35 -r e49137521123 pyikriam/example.py --- a/pyikriam/example.py Sat Nov 01 22:21:25 2008 +0800 +++ b/pyikriam/example.py Sun Nov 02 00:12:53 2008 +0800 @@ -1,8 +1,19 @@ +import sys from __init__ import Ikariam +if len(sys.argv) != 2: + print >> sys.stderr, 'Usage: %s ' % (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) -