Skip to content

Instantly share code, notes, and snippets.

@elminson
Created March 25, 2022 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elminson/bb4d91473ff9c22c3b86ce37437b217f to your computer and use it in GitHub Desktop.
Save elminson/bb4d91473ff9c22c3b86ce37437b217f to your computer and use it in GitHub Desktop.
import os
import requests
# Update a File if is older than X minutes
def update_old_file(remote_url, local_file, max_expiration_time = 10):
st = os.stat(dir_path + save_as_file)
mtime = st.st_mtime
file_age = (time.time() - mtime) / 60
if file_age > max_expiration_time:
data = requests.get(remote_url)
with open(local_file, 'wb') as file:
file.write(data.content)
remote_url = 'https://dummyimage.com/600x400/000/fff'
local_file = 'most_active.json'
max_expiration_time = 10 # in minutes
update_old_file(remote_url, local_file, max_expiration_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment