Skip to content

Instantly share code, notes, and snippets.

@yingca1
Created October 18, 2016 06:49
Show Gist options
  • Save yingca1/5ba9c2cd2854814a97f74e402b1f8eaa to your computer and use it in GitHub Desktop.
Save yingca1/5ba9c2cd2854814a97f74e402b1f8eaa to your computer and use it in GitHub Desktop.
import urllib.request
import asyncio
import json
r = urllib.request.urlopen('https://raw.githubusercontent.com/spacelan/wechat-emoticon/master/emoticons.json').read().decode('utf8')
json_obj = json.loads(r)
@asyncio.coroutine
def download(todo):
urllib.request.urlretrieve(todo.get('url'), todo.get('md5') + '.gif')
loop = asyncio.get_event_loop()
tasks = [download(todo) for todo in json_obj]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment