def __change_engines(self):
     result = post_request(CHANGE_ENGINES_URL.format(plane_id=self.plane.plane_id),
                           {'id_moteur': self.plane.replacement_engines_type})
     if not string_contains("L'avion va bien recevoir ses nouveaux moteurs, durée : 2 heures.", result):
         # TODO parse the answer
         logger.warning('Error while changing engines')
     self.__ready = False
 def __fill_fuel(self):
     fuel_qty = self.plane.fuel_capacity - self.plane.kerosene
     confirm_page = post_request(FILL_FUEL_URL.format(plane_id=self.plane.plane_id),
                                 {'cq': fuel_qty})
     if not string_contains('Vous avez ajouté .+ litres? de kérosène dans votre avion !',
                            confirm_page):
         logger.warning('Error when filling fuel')
         self.__ready = False
Example #3
0
def authenticate_with_server():
    http_session = requests.session()
    http_session.get(LOGIN_PAGE, headers=HEADER)
    data = {"pseudo": USERNAME, "passe": PASSWORD, "souvenir": 1}
    http_session.post(POST_LOGIN_PAGE, data, headers=HEADER)
    logger.warning('LOGIN')
    save_session_in_cache(http_session)
    save_session_to_db()
    return http_session
 def __do_maintenance(self):
     page = None
     try:
         page = get_request(MAINTENANCE_URL.format(plane_id=self.plane.plane_id))
         exception_if_not_contains('Votre avion est maintenant en maintenance', page)
     except:
         logger.error('Problem sending to maintenance')
         if not string_contains("en mission, en maintenance ou n'a pas plus de 100,000 km sans maintenance",
                                page):
             # case when the current airport has changed
             # case not enough mecanicians
             notify('FM : could not send to maintenance', page)
         else:
             # TODO case plane maintenance was over, should continue iteration over planes, refresh and run again
             logger.warning("Outdated plane list (not an exception anymore)")
             # raise OutdatedPlanesListException()
     self.__ready = False
Example #5
0
def __generic_request(method_name, address, post_data=None):
    http_session = get_session()
    if not http_session:
        logger.warning('No previous session found')
        http_session = authenticate_with_server()
    result = getattr(http_session, method_name)(address, data=post_data, headers=constants.HEADER).text
    if not is_connected(result):
        logger.warning('Session expired')
        http_session = authenticate_with_server()
        try:
            result = getattr(http_session, method_name)(address, data=post_data, headers=constants.HEADER).text
        except:
            wait()
            result = getattr(http_session, method_name)(address, data=post_data, headers=constants.HEADER).text
    save_session_in_cache(http_session)
    wait()
    return result