Created
July 8, 2019 08:16
-
-
Save yingziwu/8dda6cd82d0803f68b1c75d1abe8cb62 to your computer and use it in GitHub Desktop.
custome_emoji_download.py
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
#!/usr/bin/env python | |
# coding: utf-8 | |
import requests | |
import json | |
import tarfile | |
import os | |
import click | |
@click.command() | |
@click.argument('domain') | |
def main(domain): | |
custom_emojis_api = 'https://' + domain + "/api/v1/custom_emojis" | |
resp = requests.get(custom_emojis_api, timeout=15) | |
emojis = resp.json() | |
tar = tarfile.open(domain + '_emoji.tar.gz','w:gz') | |
if not os.path.exists(os.path.join('/tmp','emoji_download')): | |
os.mkdir(os.path.join('/tmp','emoji_download')) | |
for emoji in emojis: | |
shortcode = emoji['shortcode'] | |
url = emoji['url'] | |
try: | |
resp = requests.get(url, timeout=15) | |
except: | |
continue | |
file_name = shortcode + os.path.splitext(url)[-1] | |
tmp_file = os.path.join('/tmp', 'emoji_download', file_name) | |
with open(tmp_file,'wb') as f: | |
f.write(resp.content) | |
tar.add(tmp_file,arcname=file_name) | |
tar.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment