Skip to content

Instantly share code, notes, and snippets.

@voyeg3r
Created November 4, 2011 19:23
Show Gist options
  • Save voyeg3r/1340245 to your computer and use it in GitHub Desktop.
Save voyeg3r/1340245 to your computer and use it in GitHub Desktop.
Download all icons from http://thenounproject.com
import os
import requests
URL = "http://thenounproject.com/download/zipped/svg_%s.zip"
HUMAN_URL = "http://thenounproject.com/modal/%s/"
def main():
index = 0
errors = []
while True:
index += 1
filename = 'svg_%s.zip' % index
url = URL % index
if os.path.exists(filename):
continue
print "Fetching %s" % url
response = requests.get(URL % index)
if "Sorry buddy" in response.content:
link_url = HUMAN_URL % index
response = requests.get(link_url)
if not response.status_code == 200:
errors.append(index)
if index - 1 in errors:
print ("Two consecutive missing files, stopping. "
"(index was %s)" % (index - 2))
print "Missing indices:", errors[:-2]
break
print "Couldn't find anything for %s" % (URL % index)
continue
real_url = response.content.split('class="download" href="')[1]
real_url = real_url.split('" title=')[0]
print "Found %s instead" % real_url
response = requests.get('http://thenounproject.com%s' % real_url)
with open('svg_%s.zip' % index, 'w') as f:
f.write(response.content)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment