Example #1
0
def main():
    load_dotenv('.env')
    notification_manager = NotificationManager()
    data_manager = DataManager()
    # TODO: Uncomment after this month because of rate limit on sheety
    # data = data_manager.get_data()
    data = {
        "prices": [{
            "id": 1,
            "city": "Paris",
            "iataCode": "",
            "lowestPrice": 100
        }, {
            "id": 2,
            "city": "Berlin",
            "iataCode": "",
            "lowestPrice": 100
        }]
    }
    flight_search = FlightSearch()
    for destination in data['prices']:
        code = ""
        try:
            if destination['iataCode'] == '':
                code = flight_search.get_iata(city_name=destination['city'])
            else:
                code = destination['iataCode']
        except KeyError:
            code = flight_search.get_iata(city_name=destination['city'])
        finally:
            cheapest_flight = flight_search.get_price(origin=MY_LOCATION,
                                                      destination=code)
            price = cheapest_flight['price']
            body = {
                "price": {
                    "id": destination['id'],
                    "city": destination['city'],
                    "iataCode": code,
                    "lowestPrice": price
                },
            }
            if price < destination['lowestPrice']:
                message = f"Low Price Alert: Only €{price} to fly from {MY_CITY} " \
                          f"to {destination['city']}-{cheapest_flight['flyTo']}! between " \
                          f"{cheapest_flight['utc_departure'].split('T')[0]} and " \
                          f"{cheapest_flight['utc_arrival'].split('T')[0]} "
                # TODO: Uncomment after this month because of rate limit on sheety
                print(message)
Example #2
0
#This file will need to use the DataManager,FlightSearch, FlightData, NotificationManager classes to achieve the program requirements.x
from data_manager import DataManager
from flight_search import FlightSearch

flight_search = FlightSearch()
data_manager = DataManager()
sheet_data = data_manager.get_prices()

#check if the sheet_data dictionary contains any values for the 'iatacode' field
if sheet_data[0]["iataCode"] == "":
    for row in sheet_data:
        row["iataCode"] = flight_search.get_iata(row["city"])
    print(f"sheet_data:\n {sheet_data}")

    data_manager.destination_data = sheet_data
    data_manager.update_code()

for dest in sheet_data:
    dest_iata = dest['iataCode']
    try:
        price = flight_search.search_flight(dest_iata)['data'][0]['price']
    except:
        price = 10000

    #print all flights that meet the lowest price
    if dest['lowestPrice'] > price:
        print("{}: ${}".format(dest['city'], price))