# HG changeset patch # User Thinker K.F. Li # Date 1225733324 -28800 # Node ID 550e20dd757321b5d3654d77931c589c2cbab30c # Parent 5f94d8d8370a5a8e5db439549e8a2615fe954438 Handle more building type diff -r 5f94d8d8370a -r 550e20dd7573 pyikriam/buildings.py --- 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