Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _build(self, planet_id, object_id, nbr=None, cancel=False):
if object_id in constants.Buildings.values() or object_id in constants.Facilities.values():
self.build_building(planet_id, object_id, cancel=cancel)
elif object_id in constants.Research.values():
self.build_technology(planet_id, object_id, cancel=cancel)
elif object_id in constants.Ships.values():
self.build_ships(planet_id, object_id, nbr)
elif object_id in constants.Defense.values():
self.build_defense(planet_id, object_id, nbr)
def build_defense(self, planet_id, defense_id, nbr):
"""Build a defense unit."""
if defense_id not in constants.Defense.values():
raise BAD_DEFENSE_ID
url = self.get_url('defense', {'cp': planet_id})
res = self.session.get(url).content
if not self.is_logged(res):
raise NOT_LOGGED
soup = BeautifulSoup(res, 'html.parser')
form = soup.find('form')
token = form.find('input', {'name': 'token'}).get('value')
payload = {'menge': nbr,
'modus': 1,
'token': token,
'type': defense_id}
self.session.post(url, data=payload)