From 05c91147d94595c84e83737b06ef061321a0347d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Sat, 15 May 2021 10:28:08 +0200 Subject: [PATCH] mtime tune --- cron.sh | 1 - updater.py | 17 ++++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cron.sh b/cron.sh index 63412b3..99a2a25 100755 --- a/cron.sh +++ b/cron.sh @@ -5,7 +5,6 @@ TIME=`(time python3 updater.py ) 2>&1` # add every new file git add raw git add craft -git add last-modified.db git commit -m 'daily cron' -m "$TIME" git push diff --git a/updater.py b/updater.py index 4a30691..956f69c 100644 --- a/updater.py +++ b/updater.py @@ -80,11 +80,13 @@ class Updater(object): dst = f"{config.raw}/{path.replace('/', '_')}.json" - # mtime to datetime from timestamp, default tz, replace to GMT, format - modified = datetime.datetime.fromtimestamp(os.path.getmtime(dst)).astimezone().replace(tzinfo=pytz.timezone('GMT')).strftime(self.RFC2616) - self.last_modified[path] = modified - - return self.last_modified[path] + try: + # mtime to datetime from timestamp, default tz, replace to GMT, format + modified = datetime.datetime.fromtimestamp(os.path.getmtime(dst)).astimezone().replace(tzinfo=pytz.timezone('GMT')).strftime(self.RFC2616) + self.last_modified[path] = modified + return self.last_modified[path] + except FileNotFoundError: + return None def set_last_modified(self, path: str, modified: str): @@ -115,9 +117,6 @@ class Updater(object): response = self.api_call(api['path'], api['namespace'], access_token, headers=headers) - log(response.status_code, api) - log(response.request.headers) - log(response.headers) if response.status_code == 200: self.save_raw(api['path'], response) self.set_last_modified(api['path'], response.headers['Last-Modified']) @@ -163,4 +162,4 @@ if __name__ == "__main__": updater = Updater(region) updater.iterate_index() - updater.iterate_links() + #updater.iterate_links()