Add debug mode for GTFS scripts

This commit is contained in:
Emmy D'Anello 2024-05-08 10:38:28 +02:00
parent 2277d2fe64
commit 820fc0cc19
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 7 additions and 2 deletions

View File

@ -24,6 +24,7 @@ class Command(BaseCommand):
} }
def add_arguments(self, parser): 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('--bulk_size', type=int, default=1000, help="Number of objects to create in bulk.")
parser.add_argument('--dry-run', action='store_true', parser.add_argument('--dry-run', action='store_true',
help="Do not update the database, only print what would be done.") help="Do not update the database, only print what would be done.")

View File

@ -22,9 +22,9 @@ class Command(BaseCommand):
} }
def add_arguments(self, parser): 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(): for feed_type, feed_url in self.GTFS_RT_FEEDS.items():
self.stdout.write(f"Updating {feed_type} feed...") self.stdout.write(f"Updating {feed_type} feed...")
feed_message = FeedMessage() feed_message = FeedMessage()
@ -32,6 +32,10 @@ class Command(BaseCommand):
stop_times_updates = [] 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: for entity in feed_message.entity:
if entity.HasField("trip_update"): if entity.HasField("trip_update"):
trip_update = entity.trip_update trip_update = entity.trip_update