Move the feed .zip file to /tmp. Add debug info on refresh.

This commit is contained in:
Nahuel Lofeudo 2023-06-24 05:55:23 +01:00
parent f8857b3015
commit 12cb88ed20
2 changed files with 8 additions and 3 deletions

View File

@ -22,13 +22,13 @@ class GTFSClient():
self.stop_codes = stop_codes self.stop_codes = stop_codes
self.routes_for_stops = routes_for_stops self.routes_for_stops = routes_for_stops
feed_name = feed_url.split('/')[-1] feed_name = '/tmp/' + feed_url.split('/')[-1]
self.gtfs_r_url = gtfs_r_url self.gtfs_r_url = gtfs_r_url
self.gtfs_r_api_key = gtfs_r_api_key self.gtfs_r_api_key = gtfs_r_api_key
# Make sure that the feed file is up to date # Make sure that the feed file is up to date
try: try:
last_mtime = os.stat(feed_name).st_mtime last_mtime = int(os.stat(feed_name).st_mtime)
except: except:
last_mtime = 0 last_mtime = 0

View File

@ -51,7 +51,9 @@ def update_local_file_from_url_v1(last_mtime, local_file, url):
# If file is newer than last one we saw, get it # If file is newer than last one we saw, get it
updated = False updated = False
if mtime > int(last_mtime): print('Comparing feed mtimes: feed: {} vs remote {}'.format(str(last_mtime), str(mtime)), file=sys.stderr)
if not last_mtime or mtime > int(last_mtime):
print('Refreshing feed..', file=sys.stderr)
updated = True updated = True
r2 = requests.get(url) # download the new file content r2 = requests.get(url) # download the new file content
if r2.status_code != requests.codes.ok: if r2.status_code != requests.codes.ok:
@ -62,6 +64,9 @@ def update_local_file_from_url_v1(last_mtime, local_file, url):
# write new content to local file # write new content to local file
write_file_with_time(local_file, r2.content, mtime) write_file_with_time(local_file, r2.content, mtime)
print('Downloaded {}.'.format(local_file), file=sys.stderr)
else:
print('No need to refresh feed.', file=sys.stderr)
return updated, mtime return updated, mtime