Created
May 25, 2016 06:22
-
-
Save ekiro/eb760065619a34c7fa2ba88098af0f74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gevent import monkey | |
monkey.patch_all() | |
from gevent.pool import Pool | |
import json | |
import requests | |
def download_file(url): | |
r = requests.get(url) | |
if r.starts_code != 200: | |
return | |
with open(url.rsplit('/', 1)[0], 'wb') as f: | |
f.write(r.content) | |
# ['http://example.com/1.jpg', 'http://example.com/2.jpg', ] | |
urls = json.load(open('urls.json')) | |
p = Pool(20) | |
p.map(download_file, urls) | |
p.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment