Browse Source

mtime tune

main
Sergio Álvarez 5 months ago
parent
commit
05c91147d9
  1. 1
      cron.sh
  2. 17
      updater.py

1
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

17
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()
Loading…
Cancel
Save