# HG changeset patch # User "Rex Tsai " # Date 1225782826 -28800 # Node ID 4aad04928f66ab1ca5493f8952b53c236838dd0e # Parent f6836ef112037d9acbf0d6586bf93a21a46ec217# Parent 550e20dd757321b5d3654d77931c589c2cbab30c merged diff -r f6836ef11203 -r 4aad04928f66 pyikriam/buildings.py --- a/pyikriam/buildings.py Tue Nov 04 15:13:00 2008 +0800 +++ b/pyikriam/buildings.py Tue Nov 04 15:13:46 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