Last active
August 29, 2015 14:04
-
-
Save cr5315/7577e9513f6539a1ad27 to your computer and use it in GitHub Desktop.
Updated with more invalid file checking
This file contains hidden or 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 json | |
import sys | |
import urllib | |
import urllib2 | |
js = json.load(urllib2.urlopen("https://raw.githubusercontent.com/dconnolly/chromecast-backgrounds/master/backgrounds.json")) | |
count = 0 | |
validCount = 0 | |
downloader = urllib.URLopener() | |
total = len(js) | |
print "%d total wallpapers. Beginning download." % total | |
steps = total / 10 | |
print "[ ]", | |
print "\b" * 12, | |
sys.stdout.flush() | |
for i in js: | |
url = i["url"] | |
filename = url[url.rfind("/") + 1:] | |
try: | |
if not "." in filename: | |
raise Exception("No file extension") | |
else: | |
downloader.retrieve(url, filename) | |
validCount += 1 | |
except: | |
pass | |
count += 1 | |
if count % steps == 0: | |
print "\b.", | |
sys.stdout.flush() | |
print "\b] Downloaded %d wallpapers. %d failed to download." % (validCount, count - validCount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment