External DB init changes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user