changeset 162:e49137521123

pyikriam retrive information about land positions. - It retrive type of building on positions.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 02 Nov 2008 00:12:53 +0800
parents 1507c2d16b35
children 4f06f72365fa ba03aa8abdb2
files pyikriam/__init__.py pyikriam/example.py
diffstat 2 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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 <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)
 
-