diff --git a/gtfs_client.py b/gtfs_client.py index bad1b83..abb570d 100644 --- a/gtfs_client.py +++ b/gtfs_client.py @@ -22,13 +22,13 @@ class GTFSClient(): self.stop_codes = stop_codes 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_api_key = gtfs_r_api_key # Make sure that the feed file is up to date try: - last_mtime = os.stat(feed_name).st_mtime + last_mtime = int(os.stat(feed_name).st_mtime) except: last_mtime = 0 diff --git a/refresh_feed.py b/refresh_feed.py index abd72c4..2d2b94c 100644 --- a/refresh_feed.py +++ b/refresh_feed.py @@ -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 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 r2 = requests.get(url) # download the new file content 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_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