Skip to content

Instantly share code, notes, and snippets.

@asottile
Created September 6, 2019 21:40
Show Gist options
  • Save asottile/4715e8a68f924c4897952ebca05d30f3 to your computer and use it in GitHub Desktop.
Save asottile/4715e8a68f924c4897952ebca05d30f3 to your computer and use it in GitHub Desktop.
script to export all slack emoji
import concurrent.futures
import json
import os.path
import urllib.request
token = '...'
url = f'https://slack.com/api/emoji.list?token={token}'
resp = urllib.request.urlopen(url)
emojis = json.load(resp)
n = len(emojis['emoji'])
def dl_emoji(k, v):
if not v.startswith('https://'):
with open(f'data/{k}.alias', 'w') as f:
f.write(f'{v}\n')
else:
for i in range(4):
try:
resp = urllib.request.urlopen(v)
except Exception:
print(f'...retry {k} ({i})')
continue
_, ext = os.path.splitext(v)
with open(f'data/{k}{ext}', 'wb') as f:
f.write(resp.read())
return
with concurrent.futures.ThreadPoolExecutor(10) as tp:
futures = [tp.submit(dl_emoji, k, v) for k, v in emojis['emoji'].items()]
for i, _ in enumerate(concurrent.futures.as_completed(futures)):
if i % 100 == 1:
print(f'{i} / {n}...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment