Skip to content

Commit 3b1d8d4

Browse files
committed
Squash bugs
1 parent f7700ca commit 3b1d8d4

File tree

3 files changed

+171
-39
lines changed

3 files changed

+171
-39
lines changed

app.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,24 @@ def create_ical_from_selected(index):
4949

5050
df = pd.read_json(df_json, orient="split")
5151

52-
# Check if custom times were provided
53-
custom_departure = request.form.get("custom_departure")
54-
custom_arrival = request.form.get("custom_arrival")
55-
56-
if custom_departure and custom_arrival:
57-
# Update the DataFrame with custom times
58-
df.at[index, "scheduled_departure"] = custom_departure
59-
df.at[index, "scheduled_arrival"] = custom_arrival
52+
# Check if any custom fields were provided (user edited the flight)
53+
custom_fields = {
54+
"flight_number": request.form.get("flight_number"),
55+
"airline_name": request.form.get("airline_name"),
56+
"origin_airport": request.form.get("origin_airport"),
57+
"origin_airport_code": request.form.get("origin_airport_code"),
58+
"destination_airport": request.form.get("destination_airport"),
59+
"destination_airport_code": request.form.get("destination_airport_code"),
60+
"scheduled_departure": request.form.get("scheduled_departure"),
61+
"scheduled_arrival": request.form.get("scheduled_arrival"),
62+
"origin_timezone": request.form.get("origin_timezone"),
63+
"destination_timezone": request.form.get("destination_timezone"),
64+
}
65+
66+
# Update the DataFrame with custom fields if they were provided
67+
for field, value in custom_fields.items():
68+
if value:
69+
df.at[index, field] = value
6070

6171
ics_data = make_ics_from_selected_df_index(df, index)
6272
flight = df.iloc[index]["flight_number"]

core.py

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def get_flight(flight_number: str, date: str) -> pd.DataFrame:
5353
flight_number = parse_flight_number(flight_number)
5454
date = parse_date(date)
5555
flight_info = find_flights_with_date(flight_number, date)
56+
57+
# Normalize flight_info to a list if it's a dict
58+
if isinstance(flight_info, dict):
59+
flight_info = list(flight_info.values())
60+
5661
if not flight_info:
5762
try:
5863
flight_info = find_flight_no_date(flight_number)
@@ -123,7 +128,66 @@ def parse_flight_info(flight_info: dict, chosen_flight_index: int) -> dict:
123128
+ " "
124129
+ flight_info[n]["time"]["scheduled"]["arrival_time"]
125130
)
126-
airline_name = flight_info[n]["airline"]["name"]
131+
# Handle cases where airline is 'None' string or missing
132+
airline = flight_info[n].get("airline")
133+
if isinstance(airline, dict) and airline.get("name"):
134+
airline_name = airline["name"]
135+
else:
136+
# Try to extract airline code from flight number (e.g., "BA" from "BA929")
137+
match = re.match(r"([A-Z]+)", flight_number)
138+
if match:
139+
airline_code = match.group(1)
140+
# Map common airline codes to names
141+
airline_map = {
142+
"BA": "British Airways",
143+
"AA": "American Airlines",
144+
"UA": "United Airlines",
145+
"LH": "Lufthansa",
146+
"AF": "Air France",
147+
"KL": "KLM",
148+
"IB": "Iberia",
149+
"AS": "Alaska Airlines",
150+
"DL": "Delta Air Lines",
151+
"SW": "Southwest Airlines",
152+
"EK": "Emirates",
153+
"QF": "Qantas",
154+
"SQ": "Singapore Airlines",
155+
"NH": "All Nippon Airways",
156+
"CX": "Cathay Pacific",
157+
"AC": "Air Canada",
158+
"OS": "Austrian Airlines",
159+
"AZ": "Alitalia",
160+
"BE": "Brussels Airlines",
161+
"CA": "Air China",
162+
"CI": "China Airlines",
163+
"CM": "China Eastern Airlines",
164+
"CZ": "China Southern Airlines",
165+
"EY": "Etihad Airways",
166+
"FI": "Icelandair",
167+
"GA": "Garuda Indonesia",
168+
"G3": "GOL",
169+
"HA": "Hawaiian Airlines",
170+
"JL": "Japan Airlines",
171+
"LA": "LATAM Airlines",
172+
"LX": "Swiss International Air Lines",
173+
"MH": "Malaysia Airlines",
174+
"NZ": "Air New Zealand",
175+
"PR": "Philippine Airlines",
176+
"QR": "Qatar Airways",
177+
"RJ": "Royal Jordanian",
178+
"SK": "SAS",
179+
"SN": "Brussels Airlines",
180+
"TG": "Thai Airways",
181+
"TK": "Turkish Airlines",
182+
"TP": "TAP Air Portugal",
183+
"VN": "Vietnam Airlines",
184+
"VX": "Virgin America",
185+
"WN": "Southwest Airlines",
186+
}
187+
airline_name = airline_map.get(airline_code, f"Airline ({airline_code})")
188+
else:
189+
airline_name = "Unknown Airline"
190+
127191
origin_airport = flight_info[n]["airport"]["origin"]["name"]
128192
destination_airport = flight_info[n]["airport"]["destination"]["name"]
129193
origin_timezone = flight_info[n]["airport"]["origin"]["timezone"]["name"]
@@ -186,17 +250,20 @@ def find_flight_no_date(flight_number: str):
186250
return flight_info
187251

188252

189-
def drop_ununique_flights(flight_info: dict) -> dict:
253+
def drop_ununique_flights(flight_info) -> list:
190254
# only keeps flights which have a different scheduled departure time (ignoring date)
191255
unique_departure_times = set()
192256
unique_flights = []
193-
for flight in flight_info:
257+
# Handle both list and dict returns from the API
258+
flights_list = (
259+
flight_info if isinstance(flight_info, list) else list(flight_info.values())
260+
)
261+
for flight in flights_list:
194262
departure_time = flight["time"]["scheduled"]["departure_time"]
195263
if departure_time not in unique_departure_times:
196264
unique_departure_times.add(departure_time)
197265
unique_flights.append(flight)
198-
flight_info = unique_flights
199-
return flight_info
266+
return unique_flights
200267

201268

202269
def move_flight_date(flight_info: dict, date: str):

templates/select_flight.html

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@
9898
text-decoration: underline;
9999
}
100100

101-
.clock-icon {
101+
.edit-icon {
102102
cursor: pointer;
103103
font-size: 1.2rem;
104104
margin-left: 10px;
105105
display: inline-block;
106106
transition: transform 0.2s ease;
107107
}
108108

109-
.clock-icon:hover {
109+
.edit-icon:hover {
110110
transform: scale(1.2);
111111
}
112112

@@ -123,12 +123,14 @@
123123

124124
.modal-content {
125125
background-color: white;
126-
margin: 10% auto;
126+
margin: 5% auto;
127127
padding: 30px;
128128
border-radius: 10px;
129129
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
130130
width: 90%;
131-
max-width: 400px;
131+
max-width: 500px;
132+
max-height: 80vh;
133+
overflow-y: auto;
132134
}
133135

134136
.close {
@@ -221,37 +223,59 @@ <h1>Available Flights</h1>
221223
{% for flight in flights %}
222224
<div class="card">
223225
<h2>{{ flight.flight_number }}
224-
<span class="clock-icon" onclick="openEditModal({{ loop.index0 }})" title="Edit times">🕒</span>
226+
<span class="edit-icon" onclick="openEditModal({{ loop.index0 }})" title="Edit flight details">✏️</span>
225227
</h2>
226-
<p>Airline: {{ flight.airline_name }}</p>
228+
<p>Airline: <span id="airline-{{ loop.index0 }}">{{ flight.airline_name }}</span></p>
227229
<p>Departure: <span id="departure-{{ loop.index0 }}">{{ flight.nice_departure_date }}</span></p>
228230
<p>Arrival: <span id="arrival-{{ loop.index0 }}">{{ flight.nice_arrival_date }}</span></p>
229-
<p>From: {{ flight.origin_airport_code }}</p>
230-
<p>To: {{ flight.destination_airport_code }}</p>
231+
<p>From: <span id="from-{{ loop.index0 }}">{{ flight.origin_airport_code }}</span></p>
232+
<p>To: <span id="to-{{ loop.index0 }}">{{ flight.destination_airport_code }}</span></p>
231233
<form action="/create_event/{{ loop.index0 }}" method="post" id="form-{{ loop.index0 }}">
232-
<input type="hidden" name="flight_number" value="{{ flight.flight_number }}">
233-
<input type="hidden" name="flight_date" value="{{ flight.scheduled_departure }}">
234-
<input type="hidden" name="custom_departure" id="custom-departure-{{ loop.index0 }}" value="">
235-
<input type="hidden" name="custom_arrival" id="custom-arrival-{{ loop.index0 }}" value="">
234+
<input type="hidden" name="flight_number" id="hidden-flight-number-{{ loop.index0 }}" value="{{ flight.flight_number }}">
235+
<input type="hidden" name="airline_name" id="hidden-airline-{{ loop.index0 }}" value="{{ flight.airline_name }}">
236+
<input type="hidden" name="origin_airport" id="hidden-origin-airport-{{ loop.index0 }}" value="{{ flight.origin_airport }}">
237+
<input type="hidden" name="origin_airport_code" id="hidden-origin-code-{{ loop.index0 }}" value="{{ flight.origin_airport_code }}">
238+
<input type="hidden" name="destination_airport" id="hidden-destination-airport-{{ loop.index0 }}" value="{{ flight.destination_airport }}">
239+
<input type="hidden" name="destination_airport_code" id="hidden-destination-code-{{ loop.index0 }}" value="{{ flight.destination_airport_code }}">
240+
<input type="hidden" name="scheduled_departure" id="hidden-scheduled-departure-{{ loop.index0 }}" value="{{ flight.scheduled_departure }}">
241+
<input type="hidden" name="scheduled_arrival" id="hidden-scheduled-arrival-{{ loop.index0 }}" value="{{ flight.scheduled_arrival }}">
242+
<input type="hidden" name="origin_timezone" id="hidden-origin-tz-{{ loop.index0 }}" value="{{ flight.origin_timezone }}">
243+
<input type="hidden" name="destination_timezone" id="hidden-destination-tz-{{ loop.index0 }}" value="{{ flight.destination_timezone }}">
236244
<input type="submit" value="Create Event">
237245
</form>
238246
</div>
239247
{% endfor %}
240248
</div>
241249
<button class="restart-button" onclick="window.location.href='/'">Restart</button>
242250

243-
<!-- Time Edit Modal -->
251+
<!-- Edit Flight Details Modal -->
244252
<div id="editModal" class="modal">
245253
<div class="modal-content">
246254
<span class="close" onclick="closeEditModal()">&times;</span>
247-
<h2>Edit Flight Times</h2>
255+
<h2>Edit Flight Details</h2>
256+
<label for="modal-flight-number">Flight Number:</label>
257+
<input type="text" id="modal-flight-number" placeholder="e.g., BA929">
258+
<label for="modal-airline">Airline Name:</label>
259+
<input type="text" id="modal-airline" placeholder="e.g., British Airways">
260+
<label for="modal-origin-airport">Origin Airport:</label>
261+
<input type="text" id="modal-origin-airport" placeholder="e.g., Hannover Langenhagen Airport">
262+
<label for="modal-origin-code">Origin Airport Code:</label>
263+
<input type="text" id="modal-origin-code" placeholder="e.g., HAJ">
264+
<label for="modal-destination-airport">Destination Airport:</label>
265+
<input type="text" id="modal-destination-airport" placeholder="e.g., London Heathrow Airport">
266+
<label for="modal-destination-code">Destination Airport Code:</label>
267+
<input type="text" id="modal-destination-code" placeholder="e.g., LHR">
248268
<label for="modal-departure">Departure Time:</label>
249269
<input type="text" id="modal-departure" placeholder="yyyy-mm-dd hh:mm" pattern="\d{4}-\d{2}-\d{2} \d{2}:\d{2}" title="Format: yyyy-mm-dd hh:mm (24-hour)">
250270
<label for="modal-arrival">Arrival Time:</label>
251271
<input type="text" id="modal-arrival" placeholder="yyyy-mm-dd hh:mm" pattern="\d{4}-\d{2}-\d{2} \d{2}:\d{2}" title="Format: yyyy-mm-dd hh:mm (24-hour)">
272+
<label for="modal-origin-timezone">Origin Timezone:</label>
273+
<input type="text" id="modal-origin-timezone" placeholder="e.g., Europe/Berlin">
274+
<label for="modal-destination-timezone">Destination Timezone:</label>
275+
<input type="text" id="modal-destination-timezone" placeholder="e.g., Europe/London">
252276
<div class="button-group">
253277
<button class="cancel-button" onclick="closeEditModal()">Cancel</button>
254-
<button class="save-button" onclick="saveEditedTimes()">Save</button>
278+
<button class="save-button" onclick="saveEditedDetails()">Save</button>
255279
</div>
256280
</div>
257281
</div>
@@ -272,10 +296,11 @@ <h2>Edit Flight Times</h2>
272296
function openEditModal(index) {
273297
currentEditingIndex = index;
274298
const modal = document.getElementById('editModal');
299+
const flight = flights[index];
275300

276301
// Parse the current times
277-
const departure = flights[index].scheduled_departure;
278-
const arrival = flights[index].scheduled_arrival;
302+
const departure = flight.scheduled_departure;
303+
const arrival = flight.scheduled_arrival;
279304

280305
// Convert from "YYYYMMDD HHMM" to "YYYY-MM-DD HH:MM" format
281306
const depDateTime = departure.substring(0, 4) + '-' + departure.substring(4, 6) + '-' +
@@ -285,8 +310,17 @@ <h2>Edit Flight Times</h2>
285310
arrival.substring(6, 8) + ' ' + arrival.substring(9, 11) + ':' +
286311
arrival.substring(11, 13);
287312

313+
// Populate modal fields with current flight data
314+
document.getElementById('modal-flight-number').value = flight.flight_number;
315+
document.getElementById('modal-airline').value = flight.airline_name;
316+
document.getElementById('modal-origin-airport').value = flight.origin_airport;
317+
document.getElementById('modal-origin-code').value = flight.origin_airport_code;
318+
document.getElementById('modal-destination-airport').value = flight.destination_airport;
319+
document.getElementById('modal-destination-code').value = flight.destination_airport_code;
288320
document.getElementById('modal-departure').value = depDateTime;
289321
document.getElementById('modal-arrival').value = arrDateTime;
322+
document.getElementById('modal-origin-timezone').value = flight.origin_timezone;
323+
document.getElementById('modal-destination-timezone').value = flight.destination_timezone;
290324

291325
modal.style.display = 'block';
292326
}
@@ -296,14 +330,24 @@ <h2>Edit Flight Times</h2>
296330
currentEditingIndex = null;
297331
}
298332

299-
function saveEditedTimes() {
333+
function saveEditedDetails() {
300334
if (currentEditingIndex === null) return;
301335

336+
const index = currentEditingIndex;
337+
const flightNumber = document.getElementById('modal-flight-number').value;
338+
const airline = document.getElementById('modal-airline').value;
339+
const originAirport = document.getElementById('modal-origin-airport').value;
340+
const originCode = document.getElementById('modal-origin-code').value;
341+
const destinationAirport = document.getElementById('modal-destination-airport').value;
342+
const destinationCode = document.getElementById('modal-destination-code').value;
302343
const depValue = document.getElementById('modal-departure').value;
303344
const arrValue = document.getElementById('modal-arrival').value;
345+
const originTimezone = document.getElementById('modal-origin-timezone').value;
346+
const destinationTimezone = document.getElementById('modal-destination-timezone').value;
304347

305-
if (!depValue || !arrValue) {
306-
alert('Please fill in both departure and arrival times.');
348+
// Validate required fields
349+
if (!flightNumber || !airline || !depValue || !arrValue || !originTimezone || !destinationTimezone) {
350+
alert('Please fill in all required fields.');
307351
return;
308352
}
309353

@@ -331,13 +375,24 @@ <h2>Edit Flight Times</h2>
331375
const arrTime = arrParts[1].replace(/:/g, '');
332376
const arrFormatted = arrDate + ' ' + arrTime;
333377

334-
// Update hidden form fields
335-
document.getElementById('custom-departure-' + currentEditingIndex).value = depFormatted;
336-
document.getElementById('custom-arrival-' + currentEditingIndex).value = arrFormatted;
378+
// Update all hidden form fields with edited data
379+
document.getElementById('hidden-flight-number-' + index).value = flightNumber;
380+
document.getElementById('hidden-airline-' + index).value = airline;
381+
document.getElementById('hidden-origin-airport-' + index).value = originAirport;
382+
document.getElementById('hidden-origin-code-' + index).value = originCode;
383+
document.getElementById('hidden-destination-airport-' + index).value = destinationAirport;
384+
document.getElementById('hidden-destination-code-' + index).value = destinationCode;
385+
document.getElementById('hidden-scheduled-departure-' + index).value = depFormatted;
386+
document.getElementById('hidden-scheduled-arrival-' + index).value = arrFormatted;
387+
document.getElementById('hidden-origin-tz-' + index).value = originTimezone;
388+
document.getElementById('hidden-destination-tz-' + index).value = destinationTimezone;
337389

338-
// Update display (keep the yyyy-mm-dd hh:mm format)
339-
document.getElementById('departure-' + currentEditingIndex).textContent = depValue;
340-
document.getElementById('arrival-' + currentEditingIndex).textContent = arrValue;
390+
// Update display
391+
document.getElementById('airline-' + index).textContent = airline;
392+
document.getElementById('departure-' + index).textContent = depValue;
393+
document.getElementById('arrival-' + index).textContent = arrValue;
394+
document.getElementById('from-' + index).textContent = originCode;
395+
document.getElementById('to-' + index).textContent = destinationCode;
341396

342397
closeEditModal();
343398
}

0 commit comments

Comments
 (0)