Created
March 25, 2022 00:44
-
-
Save elminson/bb4d91473ff9c22c3b86ce37437b217f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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