diff pyikriam/buildings.py @ 213:550e20dd7573

Handle more building type
author Thinker K.F. Li <thinker@branda.to>
date Tue, 04 Nov 2008 01:28:44 +0800
parents bf4ddf5bffb9
children 60c4b4b78a01
line wrap: on
line diff
--- a/pyikriam/buildings.py	Tue Nov 04 01:14:39 2008 +0800
+++ b/pyikriam/buildings.py	Tue Nov 04 01:28:44 2008 +0800
@@ -186,3 +186,71 @@
         pass
     pass
 
+class shipyard(building):
+    def __init__(self, city_id, idx, baseurl):
+        super(shipyard, self).__init__('shipyard', city_id, idx, baseurl)
+        pass
+    pass
+
+class empty_pos(position):
+    res_patterns = {
+        'wood': 'wood',
+        'marble': 'marble',
+        'crystal': 'glass'
+        }
+
+    def _sync(self, page_dom):
+        self.building_info = None
+        self.res_wood = 0
+        self.res_marble = 0
+        self.res_crystal = 0
+        self.building_time = 0
+        self._building_uri = None
+
+        xpath_building = '/descendant::div[@class=\'buildinginfo\']/h4/text()'
+        buildings = page_dom.xpath(xpath_building)
+        if len(buildings) == 1:
+            self.building_info = buildings[0]
+            pass
+
+        xpath_costs = '/descendant::div[@class=\'costs\']/ul/li[@class=\'%s\']/text()'
+        for res, ptn in empty_pos.res_patterns.items():
+            xpath = xpath_costs % (ptn)
+            txts = page_dom.xpath(xpath)
+            if len(txts) == 1:
+                value = int(txts[0])
+                setattr(self, 'res_' + res, value)
+                pass
+            pass
+
+        xpath = xpath_costs % ('time')
+        txts = page_dom.xpath(xpath)
+        if len(txts) == 1:
+            value = ikariam_zh_timeval(txts[0])
+            self.building_time = value
+            pass
+
+        xpath_button = '/descendant::a[@class=\'button build\']'
+        anodes = page_dom.xpath(xpath_button)
+        if len(anodes) == 1:
+            self._building_uri = anodes[0].get('href')
+            pass
+        pass
+
+    def build(self):
+        url = self._baseurl + self._building_uri
+        page = c(url).get().get_content()
+        pass
+    pass
+
+class land(empty_pos):
+    def __init__(self, city_id, idx, baseurl):
+        super(land, self).__init__('land', city_id, idx, baseurl)
+        pass
+    pass
+
+class shore(empty_pos):
+    def __init__(self, city_id, idx, baseurl):
+        super(shore, self).__init__('shore', city_id, idx, baseurl)
+        pass
+    pass