Skip to content

Instantly share code, notes, and snippets.

@apoorvagnihotri
Created June 11, 2019 16:57
Show Gist options
  • Save apoorvagnihotri/d46d0b7a660886ea5cca34deba906ab1 to your computer and use it in GitHub Desktop.
Save apoorvagnihotri/d46d0b7a660886ea5cca34deba906ab1 to your computer and use it in GitHub Desktop.
import sys
import requests
base_url = "https://x.company/media/images/home/timeline/"
count = 0
tol = 20
for i in range(200):
try:
file_url = base_url + str(i) + '.jpg'
r = requests.get(file_url, stream = True)
if count > tol:
sys.exit()
if not r.ok:
count += 1
print (f"not available {i}.jpg")
continue
with open(f"ims/im{i}.jpg","wb") as pdf:
for chunk in r.iter_content(chunk_size=1024):
count = 0
if chunk:
pdf.write(chunk)
print (f"downloaded {i}.jpg")
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment