def update_destination_code(self, data): import flight_search flight_search = flight_search.FlightSearch() for city in data: if city['iataCode'] == '': update_endpoint = f'{self.sheety_endpoint}/{city["id"]}' update_data = { 'price': { 'iataCode': flight_search.get_destination_code(city['city']) } } update_response = requests.put(update_endpoint, headers=self.sheety_header, json=update_data) update_response.raise_for_status()
import data_manager, flight_data, flight_search, json #This file will need to use the DataManager,FlightSearch, FlightData, NotificationManager classes to achieve the program requirements. dm = data_manager.DataManager() data = dm.get_data() print(data) fs = flight_search.FlightSearch(max_stay=28, min_stay=7, currency="AUD") for d in data: sample = fs.get_flight(from_city="MEL", to_city=d['iataCode'], lowest_price=d['lowestPrice'])
# make sure something was entered if email == "": print("Please enter an email address.") # check that it looks like an email address # just a simple validation, without using regular expressions elif email.find("@") == -1 or email.find(".") == -1: print("Please enter a valid email address.") else: return email # initialization prices = dm.DataManager("prices") # using a different object to handle users users = dm.DataManager("users") flight_search = fs.FlightSearch() notification_manager = nm.NotificationManager() # load the worksheets prices_sheet = prices.get_sheet() users_sheet = users.get_sheet() # just for some basic interaction print("Enter \"y\" if you want to add a new user.") choice = input("> ").lower() if choice == "y": add_new_user() # add missing codes for city in prices_sheet: if city["iataCode"] == "":
# This file will need to use the DataManager,FlightSearch, FlightData, NotificationManager classes to achieve the program requirements. import requests import os import data_manager import notification_manager import flight_search # Initialise class references flight_finder = flight_search.FlightSearch() flight_data = data_manager.DataManager() twilio = notification_manager.NotificationManager() # Load up current flight data flight_data.get_data() # Update all city codes for row in flight_data.data: #1. Update IATA Code iata_code = row['iataCode'] if len(iata_code) == 0: print(row['city']) this_code = flight_finder.get_iata_code(row['city']) print(row) row['iataCode'] = this_code print(row) flight_data.set_data(row) # 2. Get lowest price search_results = flight_finder.get_price(iata_code)
'date_to': future_date, 'nights_in_dst_from': 7, 'nights_in_dst_to': 28, 'flight_type': 'round', 'one_for_city': 1, 'adults': 1, 'curr': 'GBP' } data_manager = dm.DataManager(dm.ENDPOINT, dm.SHEET, dm.TOKEN) for row in data_manager.data['prices']: if len(row['iataCode']) != 0: continue city = row['city'] params = {'apikey': fs.API_KEY, 'location_types': 'city', 'term': city} flight_search = fs.FlightSearch(fs.API_LOCATIONS, fs.ENDPOINT, params) row['iataCode'] = flight_search.search_locations('name', city, 'code') data_manager.put_data(row) iata_codes = [row['iataCode'] for row in data_manager.data['prices']] notification_manager = nm.NotificationManager(nm.EMAIL, nm.PASSWORD) for idx, iata_code in enumerate(iata_codes): flight_params.update(fly_to=iata_code, max_stopovers=0) flight_search = fs.FlightSearch(fs.API_SEARCH, fs.ENDPOINT, flight_params) data = flight_search.data['data'] stopped = False if len(data) == 0: flight_params.update(max_stopovers=1) flight_search = fs.FlightSearch(fs.API_SEARCH, fs.ENDPOINT, flight_params)
# This program will pull information from an existing google sheet using sheety # and check current flight prices compared to threshold set in the google sheet # it will send an SMS with Twilio if current prices are lower then threshold # This file will need to use the DataManager,FlightSearch, FlightData, NotificationManager # classes to achieve the program requirements. import data_manager import flight_search from datetime import datetime, timedelta from notification_manager import NotificationManager # Create new objects of each class dm = data_manager.DataManager() fs = flight_search.FlightSearch() sheet_data = dm.get_destination_data() notification_manager = NotificationManager() print(sheet_data) # Update the IATA code in the spreadsheet if not already present for city in sheet_data: if city["iataCode"] == "": #print(f"No code for {city['city']}") city_details = fs.get_iata_code(city['city']) print(city_details['code']) city['iataCode'] = city_details['code'] dm.destination_data = sheet_data dm.update_destination_codes()
import data_manager, flight_data,flight_search,json #This file will need to use the DataManager,FlightSearch, FlightData, NotificationManager classes to achieve the program requirements. dm = data_manager.DataManager() flight_list = dm.data[] user_list = dm.get_user_data() flight_data = [] results = [] for user in user_list(): current_cities = [fd.from_city for fd in flight_data] if user['city'] not in current_cities: fs = flight_search.FlightSearch(max_stay=28,min_stay=7,currency="AUD",from_city=f"{user['city']}") flight_data.append(fs) for fd in flight_data: for f in flight_list: results.append(fd.get_flight(to_city=f['iataCode'],lowest_price=f['lowestPrice'])) for user in user_list: ints_flight = [r for r in results if r.origin_city == user['city']]