Added importation of aerodromes

This commit is contained in:
2025-09-30 20:23:15 -05:00
parent 9493fffff5
commit 30b2b76290
6 changed files with 73799 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import csv
from django.core.management.base import BaseCommand
from simulator.models import Aerodrome
class Command(BaseCommand):
help = "Import airports from airports.csv"
def handle(self, *args, **options):
with open(
"/home/rbitton/gitea/FlightGrid/data/airports.csv",
newline="",
encoding="utf-8",
) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
icao = row["ICAO"].strip()
if not icao: # skip entries without ICAO
continue
aerodrome, _ = Aerodrome.objects.update_or_create(
icao=icao,
defaults={
"iata": row["IATA"] or None,
"name": row["Name"],
"city": row["City"],
"country": row["Country"],
"latitude": float(row["Latitude"]),
"longitude": float(row["Longitude"]),
"altitude": int(float(row["Altitude"])),
},
)
self.stdout.write(self.style.SUCCESS("Import complete"))