Skip to content

Instantly share code, notes, and snippets.

@benjeffery
Last active November 13, 2015 13:46
Show Gist options
  • Save benjeffery/289ae04eb7fbf3dbc735 to your computer and use it in GitHub Desktop.
Save benjeffery/289ae04eb7fbf3dbc735 to your computer and use it in GitHub Desktop.
import requests
def dl(path, filename):
try:
r = requests.get(path, stream=True)
if r.status_code == 200:
with open(filename, 'wb') as f:
for chunk in r:
f.write(chunk)
print "done", path
else:
print "failed", path, filename
except:
print "failed", path, filename
headers = {'Authorization': 'Uploadcare.Simple KEY:KEY'}
r = requests.get("https://api.uploadcare.com/files/?limit=1000", headers=headers)
print 'index', r.status_code
index = r.json()
index = index['results']
for i in index:
try:
dl(i['original_file_url'], 'dl/'+i['uuid']+'.'+i['original_filename'].split('.')[-1])
except IndexError:
dl(i['original_file_url'], i['uuid'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment