Nov-07-2023, 02:31 PM
(This post was last modified: Nov-07-2023, 02:31 PM by jacksfrustration.)
ok so i changed the flights to print the output
the output of found flights function returns None with no pop up messages
the code for found flights follows
What am i doing wrong here?
QUick edit: after trying once more. i have found a flight using different cities but it did not save the flight in the csv file which according to the code below should have been appended to the file
the output of found flights function returns None with no pop up messages
the code for found flights follows
def output_found_flights(ent): '''connects to the api in order to find flights. information from entries are received generates values in the current entry that is supplied when the function is called and returns the updated dictionary file''' query = { "fly_from": ent['from_iata_code'], "fly_to": ent['to_iata_code'], "date_from": ent['from_time'], "date_to": ent["to_time"], "nights_in_dst_from": 7, "nights_in_dst_to": 28, "flight_type": "round", "one_for_city": 1, "max_stopovers": 0, "curr": "GBP" } headers = { "apikey": API_KEY } endpoint = "https://api.tequila.kiwi.com/v2/search" response = requests.get(url=endpoint, headers=headers, params=query) flights = response.json() try: lowest_price = round(float(ent["lowest_price"]), 2) except ValueError: messagebox.showerror(title="Ooops", message="You have not entered appropriate input for the lowest price variable") for flight in flights['data']: flight_price = round(float(flights['data'][0]['price']), 2) if flight['price'] <= lowest_price: adult_price=flights['data'][0]['fare']['adults'] children_price=flights['data'][0]['fare']['children'] infants_price=flights['data'][0]['fare']['infants'] total_price=float((adult_price * ent['adults'] ) + (children_price * ent['children']) + (infants_price * ent['infants'])) url = flights['data'][0]['deep_link'] date = flights['data'][0]['local_departure'] date_separator = date.find("T") departure_date = date[:date_separator] date_list = departure_date.split("-") date_formatted = f"{date_list[2]}/{date_list[1]}/{date_list[0]}" ent['trip_date'] = date_formatted ent["ticket_price"] = flight_price ent['total_price']=total_price ent['url'] = url try: if messagebox.askokcancel(title=f"{ent['trip_date']} from {ent['from_city_name']} to {ent['to_city_name']}",message=f"Ticket price is £{ent['total_price']}0\n" f"{int(ent['adults'])} adults are travelling with {int(ent['children'])} children and {int(ent['infants'])} infants.\nPress ok to open the URL in order to buy the tickets"): webbrowser.open(ent['url']) except ValueError: messagebox.showerror(title="Ooops",message="No flights were found") else: messagebox.showerror(title="No flight found",message="No flights found that fit your criteria")i cant understand where it is going wrong. if there are no flights then according to my try statements and if statements i should get a pop up saying no flights were found. But instead all i get is return None from the above function
What am i doing wrong here?
QUick edit: after trying once more. i have found a flight using different cities but it did not save the flight in the csv file which according to the code below should have been appended to the file
my_list=save_ent() new_list=[] for ent in my_list: new_list.append(output_found_flights(ent)) new_data_file=pd.DataFrame(new_list) new_data_file.to_csv("flight_data.csv",index=False,mode="a")