Skip to content

Instantly share code, notes, and snippets.

Created April 2, 2020 12:37
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Download every svg file from undraw.
#!/usr/bin/env python3
import os
import json
import requests
from multiprocessing.pool import ThreadPool
def build_index():
page = 1
urls = []
while True:
res = requests.get("{}".format(page))
json_body = res.json()
for item in json_body['illustrations']:
title = item['title']
url = item['image']
print("Title: %s => URL: %s" % (title, url))
urls.append([title, url])
page = json_body['nextPage']
print("Proceeding to Page %d" % page)
if not json_body['hasMore']:
print("Finished Gathering JSON.")
return urls
def download_from_entry(entry):
title, url = entry
file_name = "%s.svg" % title.lower().replace(' ', '_')
print("Downloading %s" % file_name)
if not os.path.exists(file_name):
res = requests.get(url, stream=True)
if res.status_code is 200:
path = "./images/%s" % file_name
with open(path, 'wb') as f:
for chunk in res:
return file_name
urls = build_index()
print("Downloading %d files." % len(urls))
results = ThreadPool(20).imap_unordered(download_from_entry, urls)
for path in results:
print("Downloaded %s" % path)
print("Downloaded %d files." % len(urls))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment