@@ -127,29 +127,32 @@ def run_app():
127127 edit_option , edit_index = pick (edit_options , edit_prompt )
128128
129129 if edit_option == 'flights' :
130+ attraction_choice = "N/A"
130131 flight_name_prompt = 'Which flight would you like to edit?'
131132 flight_name_options = []
132- for item in itineraries :
133- for flight in item ['flights' ]:
134- flight_name_options .append (flight ["flight name" ])
133+ for itinerary in itineraries :
134+ if itinerary ["name" ] == itinerary_option :
135+ for flight in itinerary ['flights' ]:
136+ flight_name_options .append (flight ["flight name" ])
135137 flight_choice , flight_name_index = pick (flight_name_options , flight_name_prompt )
136138 flight_prompt = 'Finally, what about the flight would you like to edit?'
137139 flight_options = ['departure airport' , 'departure date' , 'arrival airport' , 'arrival date' ]
138140 edit_option , flight_index = pick (flight_options , flight_prompt )
139141 elif edit_option == 'attractions' :
142+ flight_choice = "N/A"
140143 attraction_name_prompt = 'Which attraction would you like to edit?'
141144 attractions_available = []
142- for item in itineraries :
143- for attraction in item ['attractions' ]:
144- attractions_available .append (attraction ["attraction name" ])
145+ for itinerary in itineraries :
146+ if itinerary ["name" ] == itinerary_option :
147+ for attraction in itinerary ['attractions' ]:
148+ attractions_available .append (attraction ["attraction name" ])
145149 attraction_choice , attraction_choice_index = pick (attractions_available , attraction_name_prompt )
146150 attractions_prompt = 'Which attraction property would you like to edit?'
147151 attraction_options = ['attraction_name' , 'address' , 'summary' , 'tag(s)' ]
148152 edit_option , attraction_index = pick (attraction_options , attractions_prompt )
149153 elif edit_option != 'flights' or edit_option != 'attractions' :
150154 flight_choice = "N/A"
151155 attraction_choice = "N/A"
152- print (flight_choice )
153156
154157 edit_itinerary (itineraries , itinerary_option , edit_option , flight_choice , attraction_choice )
155158
@@ -182,6 +185,16 @@ def run_app():
182185 "arrival airport" : arrival_airport ,
183186 "arrival date" : arrival_date
184187 })
188+ # Check if flight already exists
189+ for itinerary in itineraries :
190+ for flight in itinerary ['flights' ]:
191+ if flight_name == flight ['flight name' ]:
192+ print (f"Flight '{ flight_name } ' already exists!" )
193+ flights_list_done = True
194+ break
195+ if flights_list_done :
196+ print ("Returning to main menu..." )
197+ break
185198
186199 while True :
187200 add_another_flight = input ("Would you like to add another flight? Type Y (yes) or N (no): " )
@@ -211,6 +224,16 @@ def run_app():
211224 "summary" : attraction_summary ,
212225 "tag(s)" : attraction_tags
213226 })
227+ # Check if attraction already exists
228+ for itinerary in itineraries :
229+ for attraction in itinerary ['attractions' ]:
230+ if attraction_name == attraction ['attraction name' ]:
231+ print (f"Attraction '{ attraction_name } ' already exists!" )
232+ attractions_list_done = True
233+ break
234+ if attractions_list_done :
235+ print ("Returning to main menu..." )
236+ break
214237
215238 while True :
216239 add_another_attraction = input ("Would you like to add another attraction? Type Y or N:" )
@@ -229,7 +252,22 @@ def run_app():
229252 if not itineraries :
230253 print ("No itineraries available to view!" )
231254 else :
232- view_itineraries (itineraries )
255+ # Use pick module: Ask if they would like to view all itineraries, or a specific one
256+ view_prompt = 'Would you like to view all the existing itineraries?: '
257+ view_options = ['View All' , 'View One' ]
258+ option , index = pick (view_options , view_prompt )
259+ if option == 'View All' :
260+ print (f"\n Filter selected: { option } " )
261+ filter_option = "All"
262+ elif option == 'View One' :
263+ # Use pick module to select an itinerary by name and location
264+ print (f"\n Filter selected: { option } " )
265+ itinerary_choice = 'Which itinerary would you like to view?: '
266+ itinerary_options = []
267+ for trip in itineraries :
268+ itinerary_options .append (trip ["name" ])
269+ filter_option , filter_index = pick (itinerary_options , itinerary_choice )
270+ view_itineraries (itineraries , filter_option )
233271
234272 # Delete itinerary
235273 elif user_choice == "5" :
0 commit comments