Skip to content

Instantly share code, notes, and snippets.

@MKtalk
Created April 16, 2020 08:59
Show Gist options
  • Save MKtalk/c5edbe70cc5c907debefc11f8dbbf9eb to your computer and use it in GitHub Desktop.
Save MKtalk/c5edbe70cc5c907debefc11f8dbbf9eb to your computer and use it in GitHub Desktop.
file downloader
#-*- coding:utf-8 -*-
import urllib.request
import uuid
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import Pool
def get_image(url):
filename = str(uuid.uuid4())
out = f'./download/{filename}.jpg'
print(url)
urllib.request.urlretrieve(url, out)
pool = ThreadPoolExecutor(max_workers=5)
with open('./files.txt') as f:
lines = f.readlines()
pool = Pool(processes=4)
pool.map(get_image, lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment