comparison 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
comparison
equal deleted inserted replaced
212:5f94d8d8370a 213:550e20dd7573
184 def __init__(self, city_id, idx, baseurl): 184 def __init__(self, city_id, idx, baseurl):
185 super(wall, self).__init__('wall', city_id, idx, baseurl) 185 super(wall, self).__init__('wall', city_id, idx, baseurl)
186 pass 186 pass
187 pass 187 pass
188 188
189 class shipyard(building):
190 def __init__(self, city_id, idx, baseurl):
191 super(shipyard, self).__init__('shipyard', city_id, idx, baseurl)
192 pass
193 pass
194
195 class empty_pos(position):
196 res_patterns = {
197 'wood': 'wood',
198 'marble': 'marble',
199 'crystal': 'glass'
200 }
201
202 def _sync(self, page_dom):
203 self.building_info = None
204 self.res_wood = 0
205 self.res_marble = 0
206 self.res_crystal = 0
207 self.building_time = 0
208 self._building_uri = None
209
210 xpath_building = '/descendant::div[@class=\'buildinginfo\']/h4/text()'
211 buildings = page_dom.xpath(xpath_building)
212 if len(buildings) == 1:
213 self.building_info = buildings[0]
214 pass
215
216 xpath_costs = '/descendant::div[@class=\'costs\']/ul/li[@class=\'%s\']/text()'
217 for res, ptn in empty_pos.res_patterns.items():
218 xpath = xpath_costs % (ptn)
219 txts = page_dom.xpath(xpath)
220 if len(txts) == 1:
221 value = int(txts[0])
222 setattr(self, 'res_' + res, value)
223 pass
224 pass
225
226 xpath = xpath_costs % ('time')
227 txts = page_dom.xpath(xpath)
228 if len(txts) == 1:
229 value = ikariam_zh_timeval(txts[0])
230 self.building_time = value
231 pass
232
233 xpath_button = '/descendant::a[@class=\'button build\']'
234 anodes = page_dom.xpath(xpath_button)
235 if len(anodes) == 1:
236 self._building_uri = anodes[0].get('href')
237 pass
238 pass
239
240 def build(self):
241 url = self._baseurl + self._building_uri
242 page = c(url).get().get_content()
243 pass
244 pass
245
246 class land(empty_pos):
247 def __init__(self, city_id, idx, baseurl):
248 super(land, self).__init__('land', city_id, idx, baseurl)
249 pass
250 pass
251
252 class shore(empty_pos):
253 def __init__(self, city_id, idx, baseurl):
254 super(shore, self).__init__('shore', city_id, idx, baseurl)
255 pass
256 pass