From 8aff5fbf944f6d9ed7b3cc1022cfa7923769f13b Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 10 Feb 2024 19:57:03 +0100 Subject: [PATCH] Better calendar import --- .../management/commands/update_sncf_gtfs.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/sncfgtfs/management/commands/update_sncf_gtfs.py b/sncfgtfs/management/commands/update_sncf_gtfs.py index e801344..1e3d4fb 100644 --- a/sncfgtfs/management/commands/update_sncf_gtfs.py +++ b/sncfgtfs/management/commands/update_sncf_gtfs.py @@ -188,7 +188,7 @@ class Command(BaseCommand): unique_fields=['id']) calendars.clear() if calendars and not dry_run: - Calendar.objects.bulk_create(calendars, update_conflicts=True, + Calendar.objects.bulk_create(calendars.values(), update_conflicts=True, update_fields=['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'start_date', 'end_date', 'transport_type'], @@ -402,3 +402,31 @@ class Command(BaseCommand): version=feed_info_dict.get('feed_version', 1), ) ) + + # print(len(all_trips)) + # print(Trip.objects.count()) + # existing_trips = set(Trip.objects.filter( + # id__in=[trip.id for trip in all_trips]).values_list('id', flat=True)) + # new_trips = [trip.id for trip in all_trips if trip.id not in existing_trips] + # removed_trips = Trip.objects.exclude(id__in=[trip.id for trip in all_trips]) + # + # yes_ok, yes_not_ok, no_ok, no_not_ok = 0, 0, 0, 0 + # today = datetime.now().date() + # for removed_trip in removed_trips: + # trip_id = removed_trip.id.split(':')[0] + # service = removed_trip.service + # active_trip = service.dates.filter(date__gte=today, exception_type=1).exists() + # service_today = service.dates.count() == 1 and service.dates.filter(date="2024-02-05").exists() + # if trip_id != "IDFM": + # if any(tid.startswith(trip_id) for tid in new_trips): + # if active_trip: + # yes_ok += 1 + # else: + # yes_not_ok += 1 + # else: + # if active_trip: + # print("NOT FOUND WHILE VALID SERVICE", trip_id) + # no_not_ok += 1 + # else: + # no_ok += 1 + # print(yes_ok, yes_not_ok, no_ok, no_not_ok)