def move_money_to_bank(amount=None): if not amount: page = get_request(BANK_PAGE) amount = get_amount_from_regex(AIRPORT_CASH_REGEX, page) else: get_request(BANK_PAGE) result = post_request(BANK_DEPOSIT_URL, {'cq': amount}) exception_if_not_contains(BANK_DEPOSIT_SUCCESSFUL, result)
def take_concorde_from_alliance(): page = get_request(ALLIANCE_PAGE) if string_contains(CONCORDE_PANEL_AVAILABLE_HTML, page): page = get_request(ALLIANCE_CONCORDE_PANEL_URL) concorde_id = get_values_from_regex(ALLIANCE_CONCORDE_PATTERN_HTML, page)[0] page = get_request(ALLIANCE_TAKE_CONCORDE_URL.format(concorde_id=concorde_id)) # Todo check if successful return True else: return False
def parse_all_missions(): db_remove_all_missions() result = list_countries() expiry_date = get_expiry_date() staff_page = get_request(STAFF_PAGE) airport_page = get_request(AIRPORT_PAGE) current_airport = build_airport(airport_page, staff_page) country = current_airport.country for mission_type, countries_list in result.iteritems(): mission_list = list_missions(mission_type, countries_list) for a_mission_dict in mission_list: a_mission = enrich_mission_dictionary(a_mission_dict, expiry_date, country, mission_type) if is_possible_mission(a_mission) and is_interesting_mission(a_mission): db_insert_object(a_mission)
def read_mp(): result = '' pm_box_page = get_request(PM_BOX_URL) pm_ids = get_pm_ids(pm_box_page) mp_nb = len(pm_ids) for pm_id in pm_ids: page = get_request(PM_OPEN_URL.format(pm_id=pm_id)) begin = PM_BEGIN_MESSAGE_PATTERN end = PM_END_MESSAGE_PATTERN mp_content = everything_between(page, begin, end) mp_content = strip_tags(re.findall('(.[\S+\n\r\s]+)<br /><br /></td>', mp_content)[0]) result += mp_content + '\n\n\n' return { 'mp_nb': mp_nb, 'result': result }
def move_money_to_alliance(amount=None): if not amount: page = get_request(ALLIANCE_PAGE) amount = get_amount_from_regex(AIRPORT_CASH_REGEX, page) if amount > 0: result = post_request(ALLIANCE_DEPOSIT_CASH_URL, {'cq': amount}) exception_if_not_contains(ALLIANCE_DEPOSIT_SUCCESSFUL, result)
def fill_all_airports(): other_airports = get_other_airports_id() # switch on all airports for j in other_airports: switch_to_airport(j) current_airport = Airport() capacity = current_airport.get_kerosene_capacity() stock = current_airport.get_kerosene_supply() difference = capacity - stock if difference > 0: page = get_request() available_offers = extract_available_offers(page) # while difference > 0: # the list should be copied so that it's a copy that's altered if available_offers: current_offer = available_offers.pop() if difference < current_offer['quantity']: try: buy_market_kero(difference, current_offer['sell_id']) except: # plus quick refill withdraw_from_alliance(int(current_offer['price'] * difference) + 2500) buy_market_kero(difference, current_offer['sell_id']) quick_refill = get_request(QUICK_REFILL_URL) # exception_if_not_contains('Vous venez de mettre un total de') # exception_if_not_contains("aucun plein n'est possible") current_airport = Airport() capacity = current_airport.get_kerosene_capacity() stock = current_airport.get_kerosene_supply() difference = capacity - stock if difference > 0: page = get_request(SHOP_USED_KEROSENE_URL) available_offers = extract_available_offers(page) # while difference > 0: # the list should be copied so that it's a copy that's altered if available_offers: current_offer = available_offers.pop() if difference < current_offer['quantity']: try: buy_market_kero(difference, current_offer['sell_id']) except: # plus quick refill withdraw_from_alliance(int(current_offer['price'] * difference) + 2500) buy_market_kero(difference, current_offer['sell_id'])
def list_countries(): ''' returns the list of countries available for each mission_type ''' result = {} mission_types = ["4", "5"] for i in mission_types: html_page = get_request(GENERIC_MISSION_PAGE.format(mission_type=i)) result[i] = get_country_list(html_page) return result
def buy_missing_planes(plane_class, missing_units): # if amount_needed(missing_planes) < self.airport.money: # for aircraft_type, missing_units in missing_planes.iteritems(): for _ in range(missing_units): if plane_class == SupersonicPlane: if take_concorde_from_alliance(): return page = get_request(plane_class.buy_url) try: exception_if_not_contains(SHOP_SUCCESSFUL_PLANES, page, 'Could not buy a plane') except: withdraw_from_alliance(plane_class.price)
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
def planes_value(request): response = '' other_airports = get_other_airports_id() for j in other_airports: value_sum = 0 planes_nb = 0 switch_to_airport(j) current_airport = Airport() page = get_request(PLANES_PAGE) ready_planes = build_planes_from_html(page) for i in ready_planes: if i.get_value: if i.get_value(): value_sum += i.get_value() planes_nb += 1 response += '{}({}/{}) <br/><br/>'.format(current_airport.airport_name, planes_nb, current_airport.planes_capacity, format_amount(value_sum)) return HttpResponse(response)
def get_ongoing_missions(self): dashboard = get_request(MISSION_DASHBOARD) return get_ongoing_missions(dashboard)
def build_planes(self): html_page = get_request(PLANES_PAGE) planes_list = build_planes_from_html(html_page) sorted_planes = split_planes_list_by_type(planes_list) return sorted_planes
def build_airport(self): staff_page = get_request(STAFF_PAGE) airport_page = get_request(AIRPORT_PAGE) return build_airport(airport_page, staff_page)
def get_market_kero_page(): return get_request('http://localhost/AS/marketplace_kerosene_2sellers.html')
def buy_kerosene(litres): page = get_request(SHOP_KEROSENE_URL) # TODO check if there is kerosene available page = post_request(SHOP_BUY_KEROSENE_URL, {'cq': str(litres)})
def __scrap_plane(self): get_request(SCRAP_PLANE_URL.format(plane_id=self.plane.plane_id)) self.__ready = False
def withdraw_from_alliance(amount=None): if not amount: page = get_request(ALLIANCE_PAGE) # TODO Put all the amounts regex in a constant amount = get_amount_from_regex(ALLIANCE_CASH_REGEX, page) post_request(ALLIANCE_WITHDRAW_CASH_URL, {'cq': amount})
def switch_to_airport(airport_id): get_request(AIRPORT_MENU_PAGE) post_request(SWITCH_TO_AIRPORT_URL, {'id_aeroport': airport_id})
def get_other_airports_id(): page = get_request(AIRPORT_MENU_PAGE) other_airports = get_values_from_regex(AIRPORTS_ID_REGEX, page) return other_airports