Mercurial > eagle-eye
changeset 215:4aad04928f66
merged
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Tue, 04 Nov 2008 15:13:46 +0800 |
parents | f6836ef11203 (current diff) 550e20dd7573 (diff) |
children | 785c89e5db32 1b7805535040 |
files | |
diffstat | 1 files changed, 68 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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