Drop old services before updating GTFS data

This commit is contained in:
Emmy D'Anello 2024-02-10 18:30:36 +01:00
parent 6ef1df2757
commit ee5eb13a01
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 1 additions and 4 deletions

View File

@ -56,8 +56,6 @@ class Command(BaseCommand):
self.stdout.write("Updating database...") self.stdout.write("Updating database...")
all_trips = []
for transport_type, feed_url in self.GTFS_FEEDS.items(): for transport_type, feed_url in self.GTFS_FEEDS.items():
self.stdout.write(f"Downloading {transport_type} GTFS feed...") self.stdout.write(f"Downloading {transport_type} GTFS feed...")
with ZipFile(BytesIO(requests.get(feed_url).content)) as zipfile: with ZipFile(BytesIO(requests.get(feed_url).content)) as zipfile:
@ -161,6 +159,7 @@ class Command(BaseCommand):
unique_fields=['id']) unique_fields=['id'])
routes.clear() routes.clear()
Calendar.objects.filter(transport_type=transport_type).delete()
calendar_ids = [] calendar_ids = []
if "calendar.txt" in zipfile.namelist(): if "calendar.txt" in zipfile.namelist():
calendars = [] calendars = []
@ -299,8 +298,6 @@ class Command(BaseCommand):
unique_fields=['id']) unique_fields=['id'])
trips.clear() trips.clear()
all_trips.extend(trips)
stop_times = [] stop_times = []
for stop_time_dict in csv.DictReader(read_file("stop_times.txt")): for stop_time_dict in csv.DictReader(read_file("stop_times.txt")):
stop_time_dict: dict stop_time_dict: dict