Esempio n. 1
0
 def read_content(self, pages:dict):
     '''
     Reads the content of the given pages and writes them into the village.
     possible keys:
     - resources   (dorf1.php)
         resource_fields
         resources
         production
     - village (dorf2.php)
     - troops (rally_place)
     '''
     
     # dorf1.php:
     if 'resources' in pages: 
         doc = pages['resources']
         self.resource_fields = reader.read_resource_fields(doc)
         self.resources = Resources(reader.read_resources(doc))
         self.production = Resources(reader.read_production(doc))
         if not self.resources or not self.production:
             logger.log_error("page error", [ "%s: %s" % (t, p.find("html").html().strip()) for t,p in pages.items() ], 'Could not fetch village data')
             
         try:
             self.storage_capacity = Resources(reader.read_storage_capacity(doc))
             self.name = reader.read_villages(doc, True)[0]['name']
         except Exception as e:
             traceback.print_exc()
             self.storage_capacity = []
             self.name = ""
     
     # dorf2.php
     if 'village' in pages:
         doc = pages['village']
         self.buildings = reader.read_buildings(doc)