Skip to content

Instantly share code, notes, and snippets.

@yingziwu
Created July 8, 2019 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yingziwu/8dda6cd82d0803f68b1c75d1abe8cb62 to your computer and use it in GitHub Desktop.
Save yingziwu/8dda6cd82d0803f68b1c75d1abe8cb62 to your computer and use it in GitHub Desktop.
custome_emoji_download.py
#!/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