Skip to content

Instantly share code, notes, and snippets.

@cr5315
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cr5315/7577e9513f6539a1ad27 to your computer and use it in GitHub Desktop.
Save cr5315/7577e9513f6539a1ad27 to your computer and use it in GitHub Desktop.
Updated with more invalid file checking
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