def fetch_planets(self): self.logger.info('Fetching planets..') resp = self.br.open(self.PAGES['main']).read() self.calc_time(resp) soup = BeautifulSoup(resp) self.planets = [] self.moons = [] try: for i, c in enumerate(soup.findAll('a', 'planetlink')): name = c.find('span', 'planet-name').text coords = c.find('span', 'planet-koords').text[1:-1] url = c.get('href') p_id = int(c.parent.get('id').split('-')[1]) construct_mode = len(c.parent.findAll('a', 'constructionIcon')) != 0 p = Planet(p_id, name, coords, url, construct_mode) if i == 0: p.mother = True self.planets.append(p) #check if planet has moon moon = c.parent.find('a', 'moonlink') if moon and 'moonlink' in moon['class']: url = moon.get('href') m_id = url.split('cp=')[1] m = Moon(m_id, coords, url) self.moons.append(m) except: self.logger.exception('Exception while fetching planets') else: self.check_attacks(soup)
def fetch_planets(self): self.logger.info('Fetching planets..') resp = self.br.open(self.PAGES['main']).read() self.calc_time(resp) soup = BeautifulSoup(resp) self.planets = [] self.moons = [] try: for i, c in enumerate(soup.find('select').findAll('option')): url = c['value'] name, coords = c.contents[0].split(' ')[0:2] p = Planet('1', name, coords[1:-1], url, False) if i == 0: p.mother = True self.planets.append(p) #p_id = int(c.parent.get('id').split('-')[1]) # construct_mode = len( # c.parent.findAll( # 'a', # 'constructionIcon')) != 0 # check if planet has moon # moon = c.parent.find('a', 'moonlink') # if moon and 'moonlink' in moon['class']: # url = moon.get('href') # m_id = url.split('cp=')[1] # m = Moon(m_id, coords, url) # self.moons.append(m) except: self.logger.exception('Exception while fetching planets')