Skip to content

Instantly share code, notes, and snippets.

@aemxn
Created October 20, 2020 08:00
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 aemxn/7b294c1db0ed325dfb699d15bbfd38a1 to your computer and use it in GitHub Desktop.
Save aemxn/7b294c1db0ed325dfb699d15bbfd38a1 to your computer and use it in GitHub Desktop.
Download image with interval
import requests
import shutil
import time
import time
import threading
def dl():
image_url = "https://p3.fgies.com/bucket-pnb/PNB-11.jpg"
filename_jpeg = image_url.split("/")[-1]
filename_ts = filename_jpeg.split(".")[0]
named_tuple = time.localtime()
time_string = time.strftime("%Y%m%d-%H%M%S", named_tuple)
filename = filename_ts + "-" + time_string + ".jpg"
r = requests.get(image_url, stream = True)
if r.status_code == 200:
r.raw.decode_content = True
with open(filename,'wb') as f:
shutil.copyfileobj(r.raw, f)
print('Image sucessfully Downloaded: ', filename)
else:
print('Image Couldn\'t be retreived')
while True:
dl()
time.sleep(120) # 120s = 2 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment