Skip to content

Instantly share code, notes, and snippets.

@aemxn
Created October 20, 2020 08:00
Show Gist options
  • Select an option

  • Save aemxn/7b294c1db0ed325dfb699d15bbfd38a1 to your computer and use it in GitHub Desktop.

Select an option

Save aemxn/7b294c1db0ed325dfb699d15bbfd38a1 to your computer and use it in GitHub Desktop.

Revisions

  1. aemxn created this gist Oct 20, 2020.
    28 changes: 28 additions & 0 deletions dl_image.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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