Instantly share code, notes, and snippets.

What would you like to do?
import json
import logging
import os
from pathlib import Path
from urllib.request import urlopen, Request
logger = logging.getLogger(__name__)
types = {'image/jpeg', 'image/png'}
def get_links(client_id):
headers = {'Authorization': 'Client-ID {}'.format(client_id)}
req = Request('', headers=headers, method='GET')
with urlopen(req) as resp:
data = json.loads('utf-8'))
return [item['link'] for item in data['data'] if 'type' in item and item['type'] in types]
def download_link(directory, link):
download_path = directory / os.path.basename(link)
with urlopen(link) as image,'wb') as f:
f.write('Downloaded %s', link)
def setup_download_dir():
download_dir = Path('images')
if not download_dir.exists():
return download_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment