Exemplo n.º 1
0
def main():
    data_manager = DataManager()
    sheet_data = data_manager.read_data()
    flight_search = FlightSearch()
    notification_manager = NotificationManager()

    if len(sheet_data) > 0:
        for row in sheet_data:
            if row['iataCode'] == '':
                row['iataCode'] = flight_search.search_iata(row['city'])
            data_manager.destination_data = sheet_data
            data_manager.update_data()

    tomorrow = datetime.now() + timedelta(days=1)
    six_months_from_today = datetime.now() + timedelta(days=180)

    for destination in sheet_data:
        flight = flight_search.search_flights(ORIGIN_CITY_IATA,
                                              destination['iataCode'],
                                              from_time=tomorrow,
                                              to_time=six_months_from_today)
        if flight.price < destination['lowestPrice']:
            notification_manager.send_sms(
                msg=
                f'Low price alert! Only £{flight.price} to fly from {flight.origin_city}-{flight.origin_airport} '
                f'to {flight.destination_city}-{flight.destination_airport}, from {flight.out_date} '
                f'to {flight.return_date}.')
Exemplo n.º 2
0
 def update_iata_code(self, dict):
     fs = FlightSearch()
     iata_code = fs.get_code(dict['city'])
     body = {'price': {'iataCode': iata_code}}
     response = requests.put(f'{SHEETY_ENDPOINT_PRICES}/{dict["id"]}',
                             json=body,
                             headers=header)
     print(response.text)
Exemplo n.º 3
0
 def __init__(self):
     self.ui = UI()
     self.flight_data_manager = FlightDataManager()
     self.spreadsheet_data_manager = SpreadsheetDataManager(
         self.flight_data_manager)
     self.notification_manager = NotificationManager()
     self.flight_search = FlightSearch(self.spreadsheet_data_manager,
                                       self.flight_data_manager,
                                       self.notification_manager)
Exemplo n.º 4
0
def main():
    data_manager = DataManager()
    flight_search = FlightSearch()
    list_of_cities = data_manager.get_cities_from_google_sheet().json(
    )["prices"]
    for city in list_of_cities:
        # print(city["city"])
        iata = flight_search.get_iata_for_cities(
            city["city"]).json()["locations"][0]["code"]
        # print(iata)
        data_manager.add_iata_to_google_sheet(city["id"], iata)
Exemplo n.º 5
0
    def find_cheapest(self):

        for city in self.iata_prices:
            search = FlightSearch(LONDON_IATA, city)
            result = search.find_flights()
            cheapest_flight = result[0]
            for flight in result:
                if flight["price"] > cheapest_flight["price"]:
                    cheapest_flight = flight

            if self.iata_prices[city] > cheapest_flight["price"]:
                text = f"Low Price alert! Only {cheapest_flight['price']}, to fly from London-{cheapest_flight['flyFrom']} to {cheapest_flight['cityTo']}-{cheapest_flight['flyTo']}."
                print(text)
Exemplo n.º 6
0
def main():
    data_manager = DataManager()
    sheet_data = data_manager.read_data()
    flight_search = FlightSearch()
    notification_manager = NotificationManager()

    if len(sheet_data) > 0:
        for row in sheet_data:
            if row['iataCode'] == '':
                row['iataCode'] = flight_search.search_iata(row['city'])
            data_manager.destination_data = sheet_data
            data_manager.update_data()
        sheet_data = data_manager.read_data()

    destinations = {
        data["iataCode"]: {
            "id": data["id"],
            "city": data["city"],
            "price": data["lowestPrice"]
        }
        for data in sheet_data
    }

    tomorrow = datetime.now() + timedelta(days=1)
    six_months_from_today = datetime.now() + timedelta(days=180)

    for destination in destinations:
        flight = flight_search.search_flights(ORIGIN_CITY_IATA,
                                              destination['iataCode'],
                                              from_time=tomorrow,
                                              to_time=six_months_from_today)

        if flight is None:
            continue

        if flight.price < sheet_data[destination]['price']:
            users = data_manager.get_customer_emails()
            emails = [row['email'] for row in users]
            names = [row['firstName'] for row in users]

            msg = f'Low price alert! Only £{flight.price} to fly from {flight.origin_city}-{flight.origin_airport} '
            f'to {flight.destination_city}-{flight.destination_airport}, from {flight.out_date} '
            f'to {flight.return_date}.'

            if flight['stop_overs'] > 0:
                msg += f'\nFlight has {flight["stop_overs"]} stop over, via {flight["via_city"]}'

            link = f'https://www.google.co.uk/flights?hl=en#flt={flight.origin_airport}.{flight.destination_airport}' \
                   f'.{flight.out_date}*{flight.destination_airport}.{flight.origin_airport}.{flight.return_date}'

            notification_manager.send_emails(emails, msg, link)
Exemplo n.º 7
0
class App:
    def __init__(self):
        self.ui = UI()
        self.flight_data_manager = FlightDataManager()
        self.spreadsheet_data_manager = SpreadsheetDataManager(
            self.flight_data_manager)
        self.notification_manager = NotificationManager()
        self.flight_search = FlightSearch(self.spreadsheet_data_manager,
                                          self.flight_data_manager,
                                          self.notification_manager)

    # PUBLIC METHODS
    def start(self):
        self.flight_search.check_flights()
Exemplo n.º 8
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)
 def __init__(self):
     self.service = self.authentic_sheets()
     self.prices = self.get_prices_list(self.service)
     self.city_list = self.get_city_list(self.service)
     self.IATA_list = FlightSearch.iataassign(self.city_list)
     self.value_range_body_city_list_IATA = {
         "majorDimension": "COLUMNS",
         "values": [self.IATA_list]
     }
Exemplo n.º 10
0
def main():
    flight_search = FlightSearch()
    data_manager = DataManager()
    notification_manager = NotificationManager()
    data = data_manager.get_data()["prices"]

    # Get IATA Codes for cities in spreadsheet.
    if data[0]["iataCode"] == "":
        city_ids = [(elem["id"], elem["city"]) for elem in data]

        for elem in city_ids:
            iata = flight_search.get_iata_code_by_city(elem[1])
            body = {
                "price": {
                    "iataCode": iata,
                }
            }
            data_manager.put_data(body, elem[0])

    # Get Cheap flights from LON (London) to destinations in spread sheet.
    for destination in data:
        flight = flight_search.search_a_flight(destination["iataCode"])

        if flight is None:
            continue

        # Notify if cheap flight is found.
        if destination["lowestPrice"] > flight.price:
            message = "Low price alert!\n" \
                     f"Only {flight.price} to fly from {flight.origin_city}-{flight.origin_airport}" \
                     f" to {flight.destination_city}-{flight.destination_airport}" \
                     f" from {flight.out_date}" \
                     f" to {flight.return_date}."

            if flight.stop_overs > 0:
                message += f"\nFlight has {flight.stop_overs} stop over, via {flight.via_city}."

            # Notify me on phone
            notification_manager.send_message(message)

            #notify customers via mail
            customers = data_manager.get_users()["users"]
            notification_manager.send_emails(customers[0]["email"], flight)
Exemplo n.º 11
0
def main():
    print(f"Departure: {POINT_OF_DEPARTURE}")
    print(f"Date from: {DATE_FROM}")
    print(f"Date to: {DATE_TO}")

    # Here we load our preferred destinations from the provided google sheet.
    data_manager = DataManager(
        sheety_sheet_endpoint=SHEETY_SHEET_ENDPOINT
    )
    flight_data = data_manager.flight_data

    # Here we update our preferred destinations with IATA code if code is missing.
    updated_records = []
    for record in flight_data:
        if record.iata_code == "":
            iata_code = FlightSearch.fetch_iata_code(record.city)
            record.iata_code = iata_code
            updated_records.append(record)

    # print(updated_records)

    # Here we update our Google Sheets with the IATA Codes.
    data_manager.update_flight_data_with_iata_code(
        updated_records=updated_records
    )

    # Here we search for cheap flight.
    flight_searcher = FlightSearch(
        point_of_departure=POINT_OF_DEPARTURE,
        date_from=DATE_FROM,
        date_to=DATE_TO,
        min_nights_in_destination=MIN_NIGHTS_IN_DESTINATION,
        max_nights_in_destination=MAX_NIGHTS_IN_DESTINATION,
    )

    # Here we fetch the cheapest flights and send an SMS.
    for record in flight_data:
        record.cheapest_flight = flight_searcher.fetch_cheap_flights(record)
        if record.cheapest_flight is not None:
            NotificationManager.send_message(flight_data=record.cheapest_flight, message_to=MY_PHONE_NUMBER)
Exemplo n.º 12
0
 def __init__(self, city):
     search = FlightSearch(city)
     flights = [
         flight for flight in search.response
         if flight["availability"]["seats"]
     ]
     self.data = {
         "city_dpt": CITY,
         "city_to": city,
         "air_dpt": flights[0]["flyFrom"] if flights else "",
         "air_to": flights[0]["flyTo"] if flights else "",
         "price": flights[0]["price"] if flights else "",
         "date": flights[0]["local_departure"] if flights else "",
     }
Exemplo n.º 13
0
    def peres(self):
        self.alldata = []
        dm = DataManager()
        for city in dm.Codes_Prices:
            if len(self.alldata) == 0:
                fs = FlightSearch(city, dm.time_do, dm.time_posle,
                                  dm.Codes_Prices[city])
                fs.peresadki(city, dm.time_do, dm.time_posle,
                             dm.Codes_Prices[city])
                data = {
                    i['cityTo']: [
                        i['flyFrom'], i['price'],
                        i['local_departure'].split('T')[0], i['routes']
                    ]
                    for i in fs.peresadka if i['cityTo'] not in data.keys()
                }
                self.alldata.append(data)

                for i in self.alldata:
                    if i == {}:
                        self.alldata.remove(i)
                print(self.alldata)
        return self.alldata
Exemplo n.º 14
0
 def fill_iata_column(self):
     if self.iata_codes[0] == "":
         for flight in self.flights:
             fs = FlightSearch(flight)
             index = self.cities.index(flight['city']) + 2
             iata_data = {"flight": {"iataCode": f"{fs.iata_code}"}}
             if ENVIRONMENT == "Production":
                 iata_res = requests.put(
                     url=f"{SHEETY_URL}/flights/{index}", json=iata_data)
                 print(iata_res.text)
             else:
                 pass
         if ENVIRONMENT != "Production":
             print(f"Env: {ENVIRONMENT}")
         self.update_data()
Exemplo n.º 15
0
    def __init__(self):
        self.alldata = []
        dm = DataManager()
        for city in dm.Codes_Prices:
            fs = FlightSearch(city, dm.time_do, dm.time_posle,
                              dm.Codes_Prices[city])
            data = {
                i['cityTo']:
                [i['flyFrom'], i['price'], i['local_departure'].split('T')[0]]
                for i in fs.onewway
            }
            self.alldata.append(data)

            for i in self.alldata:
                if i == {}:
                    self.alldata.remove(i)
            print(self.alldata)
Exemplo n.º 16
0
 def create_flights(cls, IATA_list, prices):
     # kiwi response is a dit: dict_keys(['id', 'nightsInDest', 'duration', 'flyFrom', 'cityFrom', 'cityCodeFrom',
     # 'countryFrom', 'flyTo', 'cityTo', 'cityCodeTo', 'countryTo', 'distance', 'routes', 'airlines', 'pnr_count',
     # 'has_airport_change', 'technical_stops', 'price', 'bags_price', 'baglimit', 'availability',
     # 'facilitated_booking_available', 'conversion', 'quality', 'booking_token', 'deep_link', 'tracking_pixel',
     # 'transfers', 'type_flights', 'virtual_interlining', 'route', 'local_arrival', 'utc_arrival', 'local_departure',
     # 'utc_departure'])
     flights = []
     for city, price in zip(IATA_list, prices):
         FoundFlight = FlightSearch.kiwi_search(city, price)
         if not FoundFlight:
             flights.append(None)
             print(f"No flights to {city} at the set price")
         else:
             flights.append(
                 cls(FoundFlight[0]['price'], FoundFlight[0]['cityTo'],
                     FoundFlight[0]['route'][0]['local_departure'],
                     FoundFlight[0]['route'][1]['local_departure'],
                     FoundFlight[0]['deep_link']))
     return flights
Exemplo n.º 17
0
class FlightData:
    def __init__(self):
        self.flightsearch = FlightSearch()
        self.datamanager = DataManager()
        self.sheety_data = self.datamanager.get_data()

    def data(self, city_codes):
        data = {}
        min_prices = []
        out_date = []
        return_date = []
        for city in city_codes:
            self.flight_info = self.flightsearch.search_flights(city)

            price = self.flight_info["price"]
            min_prices.append(price)

            out = self.flight_info["route"][0]["local_departure"].split("T")[0]
            out_date.append(out)

            back = self.flight_info["route"][1]["local_departure"].split(
                "T")[0]
            return_date.append(back)
        data["prices"] = min_prices
        data["out date"] = out_date
        data["return date"] = return_date
        return data

    def list_cities(self):
        cities = [flight["city"] for flight in self.sheety_data["prices"]]
        return cities

    def orig_prices(self):
        orig_prices = [
            flight["lowestPrice"] for flight in self.sheety_data["prices"]
        ]
        return orig_prices
Exemplo n.º 18
0
from flight_data import FlightData
from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager

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

if sheet_data[0]["iataCode"] == "":
    for row in sheet_data:
        row["iataCode"] = flight_search.get_destination_code(row["city"])
    print(sheet_data)

    data_manager.destination_data = sheet_data
    data_manager.update_destination_codes()

print(sheet_data)
cities = [value["iataCode"] for value in sheet_data]

for i in cities:
    x = 0

    price = flight_search.get_prices(i)
    notification = NotificationManager(price.price, price.origin_city,
                                       price.origin_airport,
                                       price.destination_city,
                                       price.return_date, price.out_date,
                                       price.destination_airport, price.noinfo)

    if price.noinfo and price.price < sheet_data[x]["lowestPrice"]:
Exemplo n.º 19
0
from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager
from flight_data import FlightData

data = DataManager()
flight = FlightSearch()
notif = NotificationManager(data)

print("Welcome to Sidi Flight Club.")
print("We find the best flight deals and email you.")
first_name = input("What is your first name?"\n)
last_name = input("What is your last name?\n")
email = input("What is your email?\n")
if email != input("Type your email again.\n"):
    print("bad email")
else:
    print("You're in the club!")
    data.add_user(first_name, last_name, email)

flight_data = FlightData(data_manager=data, flight_search=flight, notif_manager=notif)
Exemplo n.º 20
0
from data_manager import DataManager
from flight_search import FlightSearch
from flight_data import FlightData
from notification_manager import NotificationManager

data_manager = DataManager()
sheet_data = data_manager.get_data()

if sheet_data[0]['iataCode'] == "":
    flight_search = FlightSearch()
    for city in sheet_data:
        city["iataCode"] = flight_search.get_city_code(city["city"])
    print(f"sheet_data:\n {sheet_data}")

    data_manager.destination_data = sheet_data
    data_manager.input_data()

flight_data = FlightData()

for city in sheet_data:
    data = flight_data.flight_info(city["iataCode"])
    if data == "unavailable":
        print(f"{city['city']}: not available, even with stopover")
        continue
    else:
        price = data["price"]
        print(f"{city['city']}: £{price}")
    if price is not None:
        if int(price) < city["lowestPrice"]:
            routes = data['route']
            depart = routes[0]['local_arrival'].split("T")[0]
Exemplo n.º 21
0
# This file will need to use the DataManager,FlightSearch, FlightData, NotificationManager classes to achieve the program requirements.
from data_manager import DataManager
from pprint import pprint

data_manager = DataManager()
sheet_data = data_manager.get_destination_data()
pprint(sheet_data)

for data in sheet_data:
    if data['iataCode'] == "":
        from flight_search import FlightSearch
        flight_search = FlightSearch()
        data['iataCode'] = flight_search.get_destination_code(data['city'])

pprint(sheet_data)
data_manager.destination_data = sheet_data
data_manager.update_destination_code()

Exemplo n.º 22
0
from datetime import datetime, timedelta
from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager
from pprint import pprint

data_manager = DataManager()
sheet_data = data_manager.get_destination_data()
flight_search = FlightSearch()
notification_manager = NotificationManager()

ORIGIN_CITY_IATA = "YYZ"

if sheet_data[0]["iataCode"] == "":
    for row in sheet_data:
        row["iataCode"] = flight_search.get_destination_code(row["city"])
    data_manager.destination_data = sheet_data
    data_manager.update_destination_codes()

tomorrow = datetime.now() + timedelta(days=1)
six_month_from_today = datetime.now() + timedelta(days=(6 * 30))
pprint(sheet_data)
for destination in sheet_data:
    flight = flight_search.check_flights(
        ORIGIN_CITY_IATA,
        destination["iataCode"],
        from_time=tomorrow,
        to_time=six_month_from_today
    )
    if flight:
        if int(flight.price)< int(destination['lowestPrice']):
Exemplo n.º 23
0
from data_manager import DataManager
from flight_search import FlightSearch
from datetime import datetime, timedelta
from notification_manager import NotificationManager

ORIGIN_CITY_CODE = "NYC"
# Step 3
data_manager = DataManager()
sheet_data = data_manager.get_data_destination()
customer_data = data_manager.get_customer_emails()
flight_search = FlightSearch()
notificator = NotificationManager()

# If the city in the spreadsheet doesn't have a IATA Code this part will get it and update the spreadsheet
for row in range(len(sheet_data)):
    if sheet_data[row]['IATA Code'] == '':
        sheet_data[row]['IATA Code'] = flight_search.get_city_code(
            sheet_data[row]['City'])
        data_manager.data_destination = sheet_data
        data_manager.update_destination_code()

# Obtain dates
tomorrow = datetime.now() + timedelta(days=1)
six_months_from_now = tomorrow + timedelta(days=(6 * 30))

found_flights = True
for destination in sheet_data:
    flight = flight_search.search_for_flight(
        ORIGIN_CITY_CODE,
        destination['IATA Code'],
        from_date=tomorrow,
Exemplo n.º 24
0
from datetime import datetime, timedelta
from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager

ORIGIN_CITY_IATA = "LON"

data_manager = DataManager()
flight_search = FlightSearch()
notification_manager = NotificationManager()

sheet_data = data_manager.get_destination_data()

if sheet_data[0]["iataCode"] == "":
    city_names = [row["city"] for row in sheet_data]
    data_manager.city_codes = flight_search.get_destination_code(city_names)
    data_manager.update_destination_codes()
    sheet_data = data_manager.get_destination_data()

destinations = {
    data["iataCode"]: {
        "id": data["id"],
        "city": data["city"],
        "price": data["lowestPrice"]
    }
    for data in sheet_data
}

tomorrow = datetime.now() + timedelta(days=1)
six_month_from_today = datetime.now() + timedelta(days=6 * 30)
Exemplo n.º 25
0
from data_manager import DataManager
from flight_data import FlightData
from notification_manager import NotificationManager
from flight_search import FlightSearch

data_manager = DataManager()
flight_data = FlightData()
flight_search = FlightSearch()

sheet_data = data_manager.get_codes()
user_data = data_manager.get_users()
notification_manager = NotificationManager()

ORIGIN_CITY = "MEL"

if sheet_data[len(sheet_data) - 1]["iataCode"] == '':
    for row in sheet_data:
        row['iataCode'] = flight_search.get_flight_code(row['destination'])
    data_manager.destination_data = sheet_data
    data_manager.update_sheet("flightList")

if user_data[len(user_data) - 1]["iataCode"] == '':
    for row in user_data:
        row['iataCode'] = flight_search.get_flight_code(row['airport'])
        row['country'] = flight_search.get_flight_country_code(row['airport'])
        row['cityName'] = flight_search.get_flight_city_name(row['airport'])

    data_manager.user_data = user_data
    data_manager.update_sheet("user")

# GET DEALS BASED ON SHEET
Exemplo n.º 26
0
from data_manager import DataManager
from flight_search import FlightSearch
from flight_data import FlightData
from notification_manager import NotificationManager

data_manager = DataManager()
flight_search = FlightSearch()
flight_data = FlightData()
notification_manager = NotificationManager()

sheet_data = data_manager.prices

SHEETY_PUT_ENDPOINT = "https://api.sheety.co/47fa3e5c564ccef88d4272e69984a527/flightDealsFinder/prices"

for row in sheet_data:
    city = row["city"]
    current_price = row["lowestPrice (inRupees)"]
    iataCode = row["iataCode"]
    row_id = row["id"]

    # Fill the IATA codes column
    if iataCode == "":
        iataCode = flight_search.iata_search(city)
        data_manager.update_sheet(row_id=row_id,
                                  params={"price": {
                                      "iataCode": iataCode
                                  }})

    # Search for the latest price
    search_results = flight_search.search(
        flight_data.fly_from, flight_data.date_from, flight_data.date_to,
Exemplo n.º 27
0
from data_manager import DataManager
from flight_search import FlightSearch

SHEETY_PRICES_ENDPOINT = decouple.config("SHEETY_PRICES_ENDPOINT")
SHEETY_USERS_ENDPOINT = decouple.config("SHEETY_USERS_ENDPOINT")
SHEETY_BEARER_TOKEN = decouple.config("SHEETY_BEARER_TOKEN")

prices_sheet = DataManager(endpoint=SHEETY_PRICES_ENDPOINT,
                           token=SHEETY_BEARER_TOKEN)
prices_sheet_data = prices_sheet.get_rows()["lowestPrice"]

users_sheet = DataManager(endpoint=SHEETY_USERS_ENDPOINT,
                          token=SHEETY_BEARER_TOKEN)
users_sheet_data = users_sheet.get_rows()["users"]

searcher = FlightSearch()


def get_IATACodes():
    for row in prices_sheet_data:
        if not row.get("iataCode"):
            row["iataCode"] = searcher.search_location(row["city"])
            payload = {"price": row}
            status = prices_sheet.edit_row(obj=payload, row_n=row["id"])
            print(status)


def get_flights():
    cheap_flights = {"cheap flights": []}
    for row in prices_sheet_data:
        city = {row["city"]: []}
Exemplo n.º 28
0
from datetime import datetime, timedelta

from dotenv import load_dotenv

from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager

load_dotenv()
CURRENCY = "GBP"
home_city_iata = os.getenv("HOME_CITY_IATA")

# This file will need to use the DataManager,FlightSearch, FlightData,
# NotificationManager classes to achieve the program requirements.
data_manager = DataManager()
flight_search = FlightSearch()
notification = NotificationManager()

data_manager.read_sheet()

date_from = (datetime.now() + timedelta(days=1)).strftime("%d/%m/%Y")
date_to = (datetime.now() + timedelta(days=(6 * 30))).strftime("%d/%m/%Y")

for row in data_manager.sheet_data:
    if not row["iataCode"]:
        row["iataCode"] = flight_search.get_city_code(row["city"])
        data_manager.update_iata(row["id"], row["iataCode"])

    flight = flight_search.get_flights(
        departure_iata=home_city_iata,
        destination_iata=row["iataCode"],
    # Search for Flights for all "City" entries in sheety spreadsheet.
    for i in sheet_data:
        flight = flight_searcher.find_flights(HOME_CITY_IATA_CODE,
                                              i['iataCode'], tomorrow_date,
                                              to_date, i['city'])
        try:
            if flight.price < i['lowestPrice']:
                dest_city = str(flight.dest_city).split("'")[1]
                notification_manager.send_notification(dest_city, flight.price)
        except AttributeError:
            continue


# Initialize objects.
data_manager = DataManager(SHEETY_ENDPOINT, SHEETY_TOKEN)
flight_searcher = FlightSearch(KIWI_API_KEY, KIWI_ENDPOINT)
notification_manager = NotificationManager(SMS_ACCOUNT_SID, SMS_AUTH_TOKEN,
                                           SOURCE_PHONE_NUMBER,
                                           DEST_PHONE_NUMBER)

#sheet_data = (data_manager.get_iata_data())
# Uncomment to test without having to make calls to sheety - free account only gets 200 API calls a month.
sheet_data = [
    {
        'city': 'Seoul',
        'iataCode': 'ICN',
        'lowestPrice': 0,
        'id': 2
    },
    {
        'city': 'Paris',
Exemplo n.º 30
0
from data_manager import DataManager
from flight_search import FlightSearch
from flight_data import FlightData

data_manager = DataManager()
flight = FlightSearch()

sheet_data = data_manager.get_destination_data()
flight_data = FlightData(sheet_data)

if sheet_data[0]["iataCode"] == "":
    for row in sheet_data:
        row["iataCode"] = flight.get_flight_search(row["city"])
    #print(sheet_data)

    data_manager.destination_data = sheet_data
    data_manager.update_destination_codes()