Created
September 5, 2021 13:42
-
-
Save BruceZhang1993/85c3394564526539cb27a3d64bb8ebcd to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
#*-- coding:utf8 -- | |
import aiohttp | |
import asyncio | |
import json | |
json_str = '' | |
async def main(): | |
session = aiohttp.ClientSession() | |
data = json.loads(json_str) | |
url = data.get('url') | |
text = data.get('text', 'emote') | |
if url is not None: | |
# 导出表情标签图标 | |
with open(f'{text}.png', 'wb') as f: | |
async with session.get(url) as response: | |
f.write(await response.read()) | |
f.flush() | |
for emote in data.get('emote'): | |
# 导出表情 | |
emote_url = emote.get('url') | |
emote_text = emote.get('meta', {}).get('alias') | |
if emote_text is None: | |
emote_text.emote.get('text').strip('[]') | |
with open(f'{emote_text}.png', 'wb') as f: | |
async with session.get(emote_url) as response: | |
f.write(await response.read()) | |
f.flush() | |
await session.close() | |
if __name__ == "__main__": | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment