Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Download all files from CloudApp
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import json
import urllib
import urllib2
from dateutil.parser import parse
PASSWORD = "superpass"
def request(url):
# Digest Authentication
authhandler = urllib2.HTTPDigestAuthHandler()
authhandler.add_password('Application', url, USERNAME, PASSWORD)
opener = urllib2.build_opener(authhandler)
opener.addheaders = [('Accept', 'application/json')]
response = urllib2.urlopen(url)
if response.getcode() == 200:
body = json.loads(
if len(body):
return body
return False
def download(url, created_at):
if not url:
return False
print 'Source: %s' % url
filename = url.split('/')[-1]
filename = urllib.unquote(filename.encode('utf-8')).decode('utf-8')
# if a file exists add created_at
if os.path.isfile(filename):
filename = '%s-%s' % (created_at, filename)
print 'Downloading... %s' % filename
urllib.urlretrieve(url, filename)
os.utime(filename, (created_at, created_at))
except IOError:
except LookupError:
if __name__ == "__main__":
page = 0
result = True
while result:
page = page + 1
result = request('' + str(page))
if not result:
for n in result:
source_url = n.get(u'source_url')
created_at = int(time.mktime(parse(n.get(u'updated_at')).timetuple()))
# print json.dumps(n, sort_keys=True, indent=4)
download(source_url, created_at)

This comment has been minimized.

Copy link

@badruk badruk commented Dec 2, 2017

Works flawlessly :)


This comment has been minimized.

Copy link

@Wolfr Wolfr commented Dec 26, 2018

Which environment is this script supposing? Python 2 or python 3? How do I download these packages, should I use PiP?


This comment has been minimized.

Copy link

@henriquebs12 henriquebs12 commented Sep 26, 2019

Thank you so much! It worked like a charm. You'll need Python 2 and the dateutil module if you are in Windows.

For those new to Python, after you install Python 2, just open your Python27/Scripts folder, open cmd from there (shift + right button) and install the module by typing pip install python-dateutil in the Windows terminal.

Then you can run the script by clicking with right button over, then "Edit with IDLE", and then Run > Run Module. Don't forget to update your USERNAME and PASSWORD in the script before running it. Also note that all the files will be downloaded in the same folder of the script, so make sure to create a folder and add the script inside before running it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.