Skip to content

Instantly share code, notes, and snippets.

@ekiro
Created May 25, 2016 06:22
Show Gist options
  • Save ekiro/eb760065619a34c7fa2ba88098af0f74 to your computer and use it in GitHub Desktop.
Save ekiro/eb760065619a34c7fa2ba88098af0f74 to your computer and use it in GitHub Desktop.
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