Skip to content

Instantly share code, notes, and snippets.

@andrealmar
Created January 27, 2017 17:34
Show Gist options
  • Save andrealmar/946930d638019387aed7c92b9de3d115 to your computer and use it in GitHub Desktop.
Save andrealmar/946930d638019387aed7c92b9de3d115 to your computer and use it in GitHub Desktop.
import logging
import os
from functools import partial
from multiprocessing.pool import Pool
from time import time
from download import setup_download_dir, get_links, download_link
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logging.getLogger('requests').setLevel(logging.CRITICAL)
logger = logging.getLogger(__name__)
def main():
ts = time()
client_id = os.getenv('IMGUR_CLIENT_ID')
if not client_id:
raise Exception("Couldn't find IMGUR_CLIENT_ID environment variable!")
download_dir = setup_download_dir()
links = get_links(client_id)
download = partial(download_link, download_dir)
with Pool(8) as p:
p.map(download, links)
logging.info('Took %s seconds', time() - ts)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment