Last active
November 13, 2015 13:46
-
-
Save benjeffery/289ae04eb7fbf3dbc735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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