External DB init changes

This commit is contained in:
James Pattinson
2025-12-04 18:29:09 +00:00
parent b6ad496cf0
commit 3780b3cf2f
4 changed files with 47 additions and 16 deletions

View File

@@ -29,13 +29,15 @@ def load_airports(db, csv_path):
batch = []
with open(csv_path, 'r', encoding='utf-8') as f:
reader = csv.DictReader(f)
reader = csv.reader(f) # CSV has no headers
for row in reader:
if len(row) < 4:
continue # Skip invalid rows
airport = Airport(
icao=row['icao'],
iata=row.get('iata') if row.get('iata') else None,
name=row['name'],
country=row['country']
icao=row[0].strip('"'),
iata=row[1].strip('"') if row[1].strip('"') else None,
name=row[2].strip('"'),
country=row[3].strip('"')
)
batch.append(airport)
loaded += 1
@@ -73,15 +75,17 @@ def load_aircraft(db, csv_path):
batch = []
with open(csv_path, 'r', encoding='utf-8') as f:
reader = csv.DictReader(f)
reader = csv.reader(f) # CSV has no headers
for row in reader:
if len(row) < 6:
continue # Skip invalid rows
aircraft = Aircraft(
icao24=row.get('icao24') if row.get('icao24') else None,
registration=row.get('registration') if row.get('registration') else None,
manufacturer_icao=row.get('manufacturericao') if row.get('manufacturericao') else None,
type_code=row.get('typecode') if row.get('typecode') else None,
manufacturer_name=row.get('manufacturername') if row.get('manufacturername') else None,
model=row.get('model') if row.get('model') else None
icao24=row[0].strip('"') if row[0].strip('"') else None,
registration=row[1].strip('"') if row[1].strip('"') else None,
manufacturer_icao=row[2].strip('"') if row[2].strip('"') else None,
type_code=row[3].strip('"') if row[3].strip('"') else None,
manufacturer_name=row[4].strip('"') if row[4].strip('"') else None,
model=row[5].strip('"') if row[5].strip('"') else None
)
batch.append(aircraft)
loaded += 1