Пример #1
0
 def loadup(self):
     """
     Loads cookies, Logins, 
     Loads all villages, events and the hero.
     """
     self.load_db()
     self.load_cookie()
     
     doc_resources = self.request_GET("/dorf1.php")
     if not len(reader.read_resource_fields(doc_resources)):
         self.clear_cookie()
         doc_resources = self.login(doc_login = doc_resources)
         self.save_cookie()
         
         if not len(reader.read_resource_fields(doc_resources)):
             logger.log_error("login failed", "The login failed")
     else:
         self.ajax_token = reader.read_ajax_token(doc_resources)
     
     village = self.request_village(None, doc_resources)
     
     other_villages = self.villages.keys() ^ { village.village_id } # all villages except the active
     
     self.request_villages(other_villages)
     self.request_hero()
     
     self.production_boost = reader.read_production_boost(doc_resources)
Пример #2
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)