Skip to content

Instantly share code, notes, and snippets.

@ArionMiles
Last active December 30, 2019 19:20
Show Gist options
  • Save ArionMiles/00dfea879a0511bbe0d47b85178d887e to your computer and use it in GitHub Desktop.
Save ArionMiles/00dfea879a0511bbe0d47b85178d887e to your computer and use it in GitHub Desktop.
Download slack custom emojis
# Author: ArionMiles (Kanishk Singh)
#
# slack_emojis.json is json data sent by emoji.adminList endpoint of slack.
# INSTRUCTIONS:
# 1. Go to https://{YOUR_SLACK}.slack.com/customize/emoji
#
# 2. Open Dev Tools -> Network -> Filter by XHR
#
# 3. Reload the page, go to "emoji.adminList?_x_id=XXXXXXXX" endpoint
#
# 4. go to Response tab -> Select all -> save to file "slack_emojis1.json"
# For multiple requests (pages) of "emoji.adminList...",
# Save them to slack_emojis2.json, slack_emojis3.json and so on.
#
# 5. Save the json files in the same path as this python file and create
# an directory called "output" in the same path.
from os import path
import json
import requests
OUTPUT_PATH = "output/{emoji_name}.{ext}"
def load_emojis_from_files(num_of_files):
emojis = list()
for i in range(1, num_of_files+1):
emojis_json = open("slack_emojis{}.json".format(i), "r")
emoji_data = json.load(emojis_json)
emojis += emoji_data["emoji"]
return emojis
def download_emojis(emojis):
saved_files = 0
for emoji in emojis:
emoji_url = emoji["url"]
emoji_name = emoji["name"]
ext = emoji_url[-3:]
file_path = OUTPUT_PATH.format(emoji_name=emoji_name, ext=ext)
if not path.exists(file_path):
imgdata = requests.get(emoji_url, stream=True)
with open(file_path, "wb+") as output:
output.write(imgdata.content)
print(f"Saved {emoji_name}.{ext}")
saved_files += 1
print(f"Saved {saved_files} new files.")
if __name__ == "__main__":
num_of_files = int(input("Number of files to load: "))
print("Loading emojis from JSON files...")
emojis = load_emojis_from_files(num_of_files)
print("Emojis loaded. Downloading...")
download_emojis(emojis)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment