Nov-07-2023, 08:58 PM
(Nov-07-2023, 06:30 PM)deanhystad Wrote: If there is nothing to write it doesn't matter how you try to write it. Fix the problem of there being nothing to write. Start by fixing saveEnt(). Should it ever return None?
i wrote the save_ent to check each entry if there is text there and if everything is completed it should output a dictionary.. here is my code
def save_ent(): '''loops through up to the range of the count variable. for each iteration the name of the entry widgets is generated and the information is added into a list of dictionaries by appending each dictionary to the list. finally it returns the list of dictiionaries. Try/except/else and if statements used to cover all scenarios when reaceiving the data. for instance some of the entries should be in a numerical format. title method is also used to write the city names in uniform format''' saved_info=[] if from_city_ent.get(): if to_city_ent.get(): from_city_name = from_city_ent.get().title() to_city_name = to_city_ent.get().title() if check_iata_code(): from_iata_code = from_iata_code_ent.get().upper() to_iata_code=to_iata_code_ent.get().upper() else: from_iata_code=get_iata_code(from_city_name) from_iata_code_ent.delete(0,END) from_iata_code_ent.insert(0,from_iata_code) to_iata_code = get_iata_code(to_city_name) to_iata_code_ent.delete(0,END) to_iata_code_ent.insert(0,to_iata_code) from_iata_code_ent.delete(0, END) to_iata_code_ent.delete(0, END) from_iata_code_ent.insert(0,from_iata_code) to_iata_code_ent.insert(0,to_iata_code) try: lowest_price = float(lowest_price_ent.get()) except ValueError: messagebox.showerror(title="Ooops", message="There is no number in the highest price entry!!") else: try: adult_tickets = int(amount_adult_ent.get()) except ValueError: messagebox.showerror(title="Ooops", message="There is no number in the adults entry!!") else: try: children_tickets = int(amount_children_ent.get()) except ValueError: messagebox.showerror(title="Ooops", message="There is no number in the children entry!!") else: try: infants_tickets = int(amount_infants_ent.get()) except ValueError: messagebox.showerror(title="Ooops", message="There is no number in the infants entry!!") else: from_time = dt.datetime.now() + dt.timedelta(days=1) to_time = dt.datetime.now() + dt.timedelta(days=(6 * 30)) finally: saved_info.append({"from_city_name": from_city_name, "from_iata_code": from_iata_code,"to_city_name": to_city_name, "to_iata_code": to_iata_code, "lowest_price": lowest_price,"from_time":from_time.strftime("%d/%m/%Y"),'to_time':to_time.strftime("%d/%m/%Y"),"adults":adult_tickets,"children":children_tickets,"infants":infants_tickets}) return saved_infoso as you can see if there are appropriate inputs on all of the entries then it outputs the list of dictionaries. It should never return None but if there is a widget empty it should cancel the output. The way im checking it now is i check if there is text in from and to citie widgets. If there are numbers in price, adults,children,infant tickets and if the city names match the corresponding iata codes. if they dont match then new iata codes are generated based on the from and to city data entered by the user. finally it appends to saved_info(list of dictionaries) all the useful data used. this gets used in the found flights function which creates a dataframe from the output of save_ent adding total price, trip date, url for booking the tickets. these values are used in the newly created dataframe to append it to the csv file. However all i get in the csv file as i said before is
Output:0
""
which is not an issue with save_ent function. i've tried printing new_list contents which should be the output of the save_ent function filtered through the found_flights function and i get a value of None. The problem has to lie somewhere between the two functions i just for the life of me cannot understand where it's going wrong as i get the pop up with the relevant information (the pop up that gets triggered from the output_found_flights function). this pop up contains the information that gets added to the list of dictionaries namely the url, trip date and total price of tickets. even though the values get reflected in the pop up the output of the functions is None which shouldnt happen. Please help this is confusing the shite out of me