From 820fc0cc19c990d30c871efe81810c81c1746b43 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Wed, 8 May 2024 10:38:28 +0200 Subject: [PATCH] Add debug mode for GTFS scripts --- sncfgtfs/management/commands/update_sncf_gtfs.py | 1 + sncfgtfs/management/commands/update_sncf_gtfs_rt.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sncfgtfs/management/commands/update_sncf_gtfs.py b/sncfgtfs/management/commands/update_sncf_gtfs.py index 7adee86..aecfc21 100644 --- a/sncfgtfs/management/commands/update_sncf_gtfs.py +++ b/sncfgtfs/management/commands/update_sncf_gtfs.py @@ -24,6 +24,7 @@ class Command(BaseCommand): } def add_arguments(self, parser): + parser.add_argument('--debug', '-d', action='store_true', help="Activate debug mode") parser.add_argument('--bulk_size', type=int, default=1000, help="Number of objects to create in bulk.") parser.add_argument('--dry-run', action='store_true', help="Do not update the database, only print what would be done.") diff --git a/sncfgtfs/management/commands/update_sncf_gtfs_rt.py b/sncfgtfs/management/commands/update_sncf_gtfs_rt.py index 24d2f79..f78c35f 100644 --- a/sncfgtfs/management/commands/update_sncf_gtfs_rt.py +++ b/sncfgtfs/management/commands/update_sncf_gtfs_rt.py @@ -22,9 +22,9 @@ class Command(BaseCommand): } def add_arguments(self, parser): - pass + parser.add_argument('--debug', '-d', action='store_true', help="Activate debug mode") - def handle(self, *args, **options): + def handle(self, debug=False, *args, **options): for feed_type, feed_url in self.GTFS_RT_FEEDS.items(): self.stdout.write(f"Updating {feed_type} feed...") feed_message = FeedMessage() @@ -32,6 +32,10 @@ class Command(BaseCommand): stop_times_updates = [] + if debug: + with open(f'feed_message-{feed_type}.txt', 'w') as f: + f.write(str(feed_message)) + for entity in feed_message.entity: if entity.HasField("trip_update"): trip_update = entity.trip_update