# HG changeset patch # User "Rex Tsai " # Date 1225557063 -28800 # Node ID 4f06f72365fadfb84f01df8eaca02cc39b7d086c # Parent 278bd36708e89198e975d7706c324cf9c40a7598# Parent e49137521123464987b4cdc232a7ffbba2cb6487 merged again diff -r 278bd36708e8 -r 4f06f72365fa pyikriam/__init__.py --- 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 diff -r 278bd36708e8 -r 4f06f72365fa pyikriam/example.py --- 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 ' % (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) -