def flightMenu(menuOption): if menuOption == 1: aircraft = input("Enter the Registration Number of the Aircraft for the Flight \n :") aircraft_id = aircraft_repository.find_id(aircraft) if type(aircraft_id) is int: pass else: print("No Aircraft with the Registration Number you entered was found") request() subMenu(2) takeoff_location = input( "Enter the takeoff_location of the Flight \n :") destination = input( "Enter the destination of the Flight \n :") takeoff_time = input("Enter the take-off time \n :") arrival_time = input("Enter the arrival time \n :") flight_no = input("Enter the Flight") flight = Flight(id=None, aircraft_id=aircraft_id, takeoff_location=takeoff_location, destination=destination, takeoff_time=takeoff_time, arrival_time=arrival_time, flight_no=flight_no, created_at=None) flight_repository.create(flight) request() subMenu(2) elif menuOption == 2: flight_no = input('Enter the Flight Number \n: ') flight = flight_repository.find(flight_no=flight_no) print(flight) request() subMenu(2) elif menuOption == 3: passenger_repository.showAll() id = int(input("Enter the ID of the Flight you want to Update \n :")) aircraft_id = input("Enter The Aircraft ID for the Flight \n :") takeoff_location = input("Enter The Takeoff Location of the Flight \n :") destination = input("Enter The Destination of the Flight \n :") takeoff_time = input("Enter Takeoff Time of the Flight \n :") arrival_time = input("Enter Arrival Time of the Flight \n :") flight_no = input("Enter the Flight Number of The Flight \n :") flight = Flight(id=None, aircraft_id=aircraft_id, takeoff_location=takeoff_location, destination=destination, takeoff_time=takeoff_time, arrival_time=arrival_time, flight_no=flight_no, created_at=None) flight_repository.update(id=id, flight=flight) request() subMenu(2) elif menuOption == 4: flight_no = input("Enter the Flight Number of the Flight you want to delete \n :") id = flight_repository.find_id(flight_no) if type(id) is int: flight = flight_repository.delete(id=id) else: flight = "Aircraft not found" print(flight) request() subMenu(2) elif menuOption == 5: flight_repository.showAll() request() subMenu(2) elif menuOption == 0: main() else: print("Please enter a valid option") subMenu(2)
def parse_response(self): response_text = self.response_text json_acceptable_string = response_text.replace("'", "\"") response_dictionary = json.loads(json_acceptable_string) for flight in response_dictionary['outboundFlights']: self.outboundFlights.append(Flight(flight)) for flight in response_dictionary['returnFlights']: self.returnFlights.append(Flight(flight))
def flightHandler(new_command): if new_command == 0: pass elif new_command == 1: aircraft_repository.show() craft_regNo = input('Enter the registration number of the aircraft: ') craft_id = aircraft_repository.findCraftId(craft_regNo) flight_no = input('Enter the flight number') departure = input('Enter your state of Departure: ') departure_time = input('Enter the departure time of flight: ') arrival = input('Enter your state of destination: ') arrival_time = input('Enter the arrival time of flight: ') flight = Flight(craft_id, flight_no, departure, departure_time, arrival, arrival_time) flight_repository.create(flight) toContinue(2) elif new_command == 2: flight_no = input('Please input the flight number: ') flight_repository.find(flight_no) toContinue(2) elif new_command == 3: flight_repository.show() flight_no = input('Enter the flight number: ') flight = flight_repository.findREC(flight_no) arrivalTime = flight[3] departureTime = flight[2] craft_regNo = input( 'Enter the registration number of the aircraft attached to flight: ' ) craft_id = aircraft_repository.findCraftId(craft_regNo) departure = input('Enter your state of Departure: ') arrival = input('Enter the arrival point: ') flight = Flight(craft_id, flight_no, departure, departureTime, arrival, arrivalTime) flight_repository.update(flight_no, flight) toContinue(2) elif new_command == 4: flight_repository.show() toContinue(2) elif new_command == 5: flight_no = input('Enter the flight number to delete the flight: ') flight_repository.delete(flight_no) toContinue(2) else: print('Your Input does not Exist') toContinue(2)
def populate() -> bool: """ populate database from all dumps :return: """ file_storage: str = current_app.config.get('FILE_STORAGE') file_parser = FileParser(storage_path=file_storage) parsed_results: dict = file_parser.parse_storage() for filename, search in parsed_results.items(): products: list = search.pop('products', []) new_search = Search(filename=filename, **search) db.session.add(new_search) db.session.commit() print(new_search) for product in products: flights: list = product.pop('flights', []) new_product = Product(search_id=new_search.id, **product) db.session.add(new_product) db.session.commit() for flight in flights: new_flight = Flight(product_id=new_product.id, **flight) db.session.add(new_flight) db.session.commit() return True
def get_flights(self, origin, dest=None): code = Iata().get_city_code(origin) #url = 'https://api.sandbox.amadeus.com/v1.2/flights/inspiration-search?apikey=r2VHFajVkYBhFLBA3bP4iw25GkXPKuBK&origin={}'.format(code) if dest: destCode = Iata().get_city_code(dest) url = 'http://min-prices.aviasales.ru/calendar_preload?origin={}&destination={}&locale=en¤cy=eur'.format( code, destCode) contents = urllib.request.urlopen(url).read() flights = json.loads(contents)['best_prices'] else: url = 'http://map.aviasales.ru/prices.json?origin_iata={}&locale=en&period=2018-12-01:month¤cy=eur'.format( code) contents = urllib.request.urlopen(url).read() flights = json.loads(contents) # res = [] # for result in json.loads(contents)['results']: # res.append(Flight(result)) res = [] for result in flights: result['origin'] = code res.append(Flight(result)) return res
def __map_selected_record_to_flight(record): if record is None: return None else: id, aircraft_id, takeoff_location, destination, takeoff_time, arrival_time, flight_no, created_at = record flight = Flight(id, aircraft_id, takeoff_location, destination, takeoff_time, arrival_time, flight_no, created_at) return flight
def create(self, flight: Flight): cursor = self.db.cursor() sql = "INSERT INTO flights(aircraft_id, takeoff_location, destination, takeoff_time, arrival_time, flight_no) " \ "VALUES(%s, %s, %s, %s, %s, %s) " val = (flight.aircraft_id, flight.takeoff_location, flight.destination, flight.takeoff_time, flight.arrival_time, flight.flight_no) cursor.execute(sql, val) self.db.commit() flight.id = cursor.lastrowid
def find(self, flight_no): cursor = self.db.cursor() sql = "SELECT a.craft_regNo, f.flight_no, f.departure, f.departureTime, f.arrival, f.arrivalTime FROM flights f JOIN aircrafts a ON a.id = f.craft_id WHERE flight_no = %s" val = (flight_no, ) cursor.execute(sql, val) result = cursor.fetchone() craft_id, flight_no, departure, departure_time, arrival, arrival_time = result flight = Flight(craft_id, flight_no, departure, departure_time, arrival, arrival_time) print(flight)
def show(self): cursor = self.db.cursor() sql = "SELECT a.craft_regNo, f.flight_no, f.departure, f.departureTime, f.arrival, f.arrivalTime FROM flights f JOIN aircrafts a ON a.id = f.craft_id" cursor.execute(sql) result = cursor.fetchall() for record in result: if record == None: print("Nothing to display") else: craft_id, flight_no, departure, departure_time, arrival, arrival_time = record flight = Flight(craft_id, flight_no, departure, departure_time, arrival, arrival_time) print(flight)
def calculate_new_cost(self, curr_state: State, flight: Flight, wait_time: int): added_cost = W_DUR * flight.get_duration() + W_PRI * flight.get_price( ) + W_WAIT * wait_time return curr_state.get_node_cost() + added_cost
def create_outgoing_flight(self, destination: any, dept_time: int, duration: int, price: float): flight = Flight(destination, dept_time, duration, price) self.add_outgoing_flight(flight)
def create_flight(self, src_code: string, dest_code: int, dept_time: int, duration: int, price: float): dest_airport = self.get_or_create_airport(dest_code) flight = Flight(dest_airport, dept_time, duration, price) self.add_flight(src_code, flight)