Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Polyterative/7b6e608bd4973998bf182dc80e0149c8 to your computer and use it in GitHub Desktop.

Select an option

Save Polyterative/7b6e608bd4973998bf182dc80e0149c8 to your computer and use it in GitHub Desktop.

Revisions

  1. Polyterative revised this gist May 12, 2021. 1 changed file with 25 additions and 22 deletions.
    47 changes: 25 additions & 22 deletions download-from-undraw.py
    Original file line number Diff line number Diff line change
    @@ -5,28 +5,30 @@
    import requests
    from multiprocessing.pool import ThreadPool


    def build_index():
    page = 1
    urls = []
    page = 1
    URLs = []

    while True:
    res = requests.get("https://undraw.co/api/illustrations?page={}".format(page))
    json_body = res.json()

    while True:
    res = requests.get("https://undraw.co/api/illustrations?page={}".format(page))
    json_body = res.json()
    for item in json_body['illos']:
    title = item['title']
    url = item['image']

    for item in json_body['illustrations']:
    title = item['title']
    url = item['image']
    print("Title: %s => URL: %s" % (title, url))
    URLs.append([title, url])

    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

    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(' ', '_')
    @@ -35,23 +37,24 @@ def download_from_entry(entry):

    if not os.path.exists(file_name):
    res = requests.get(url, stream=True)
    if res.status_code is 200:

    if res.status_code == 200:
    path = "./images/%s" % file_name

    with open(path, 'wb') as f:
    for chunk in res:
    f.write(chunk)

    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))
    print("Downloaded %d files." % len(urls))
  2. Phoomparin Mano created this gist Apr 2, 2020.
    57 changes: 57 additions & 0 deletions download-from-undraw.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    #!/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("https://undraw.co/api/illustrations?page={}".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:
    f.write(chunk)

    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))