from flight_search import FlightSearch from notification_manager import NotificationManager import json data_manager = DataManager() flight_search = FlightSearch() notification_manager = NotificationManager() google_sheet_data = data_manager.get_google_sheet_data() google_sheet_list = google_sheet_data['prices'] # only to be run once, to populate the IATA codes in the Google Sheet for item in google_sheet_list: if not item['iataCode'] == '': iata_code = flight_search.get_iata_codes(item['city']) row = item['id'] data_manager.add_iata_code_to_sheet(iata_code, row) iata_codes_max_prices = {item['iataCode']: item['lowestPrice'] for item in google_sheet_list} #print(iata_codes_max_prices) #print(google_sheet_list) for iata_code, price in iata_codes_max_prices.items(): flights_found = flight_search.search_flights(iata_code) for item in flights_found['data']: if item['price'] <= price: # only send a message for the first good deal, otherwise 700 messages would be sent price_alert_message = f"Low price alert! Only {item['price']} GBP to fly from "\
date_from = datetime.date.today() + datetime.timedelta(days=1) date_to = datetime.date.today() + datetime.timedelta(days=180) # TODO: 5. In main.py check if sheet_data contains any values for the "iataCode" key. # If not, then the IATA Codes column is empty in the Google Sheet. # In this case, pass each city name in sheet_data one-by-one to the FlightSearch class. # For now, the FlightSearch class can respond with "TESTING" instead of a real IATA code. # You should use the response from the FlightSearch class to update the sheet_data dictionary flight_search = FlightSearch() data_manager = DataManager() for row in sheet_data: if row['iataCode'] == "": # TODO 7. Pass each city name in sheet_data one-by-one to the FlightSearch class # to get the corresponding IATA code for that city using the Flight Search API. # You should use the code you get back to update the sheet_data dictionary. row['iataCode'] = flight_search.get_iata_codes(row['city']) # TODO: 6. In the DataManager Class make a PUT request and use the row id # from sheet_data to update the Google Sheet with the IATA codes. (Do this using code). # HINT: Remember to check the checkbox to allow PUT requests in Sheety. data_manager.update_destination_codes(row['iataCode'], row['id']) # TODO 8. The next step is to search for the flight prices from London (LON) # to all the destinations in the Google Sheet. In this project, # we're looking only for direct flights, that leave anytime between tomorrow and in 6 months (6x30days) time. # We're also looking for round trips that return between 7 and 28 days in length. # The currency of the price we get back should be in GBP. tequila_api_lowest_price = flight_search.search_flight_prices( row['iataCode'], date_from, date_to) # TODO 9. The final step is to check if any of the flights found are
from data_manager import DataManager from flight_search import FlightSearch from notification_manager import NotificationManager from datetime import datetime, timedelta ORIGIN_CITY = "BCN" sheety_data_manager = DataManager() sheety_data = sheety_data_manager.get_datas_from_sheety() sheety_users = sheety_data_manager.get_users_from_sheety() flight_search = FlightSearch() if sheety_data[0]['iataCode'] == '': for city in sheety_data: iata_code = flight_search.get_iata_codes(city['city']) city['iataCode'] = iata_code sheety_data_manager.update_iata_codes() tomorrow = datetime.now() + timedelta(days=1) six_month_from_today = datetime.now() + timedelta(days=(6 * 30)) message = '' for city_data in sheety_data: flights = flight_search.check_flights(from_city=ORIGIN_CITY, to_city=city_data['iataCode'], from_date=tomorrow, to_date=six_month_from_today) if flights is None: continue if flights.price < city_data['lowestPrice']: