Skip to content

Instantly share code, notes, and snippets.

@SuperShinyEyes
Last active February 1, 2017 06:37
Show Gist options
  • Save SuperShinyEyes/8ca4b1ab33446f2a3e8fad3e5a7e2d9a to your computer and use it in GitHub Desktop.
Save SuperShinyEyes/8ca4b1ab33446f2a3e8fad3e5a7e2d9a to your computer and use it in GitHub Desktop.
Download JPGs by reading a file of image URLs.
#!/usr/bin/env Python3
import requests
PATH_PREFIX = ""
FILE = "imageNames"
def downloadImage(url):
'''
Reference:
http://stackoverflow.com/questions/13137817/how-to-download-image-using-requests
'''
name = url.split("/")[-1]
path = PATH_PREFIX + name
r = requests.get(url, stream=True)
if r.status_code == 200:
print("Write %s" % path)
with open(path, 'wb') as f:
for chunk in r:
f.write(chunk)
else:
print("No write")
with open(FILE) as f:
# Remove newlines
for url in f.read().splitlines():
print(url)
downloadImage(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment