Skip to content

Instantly share code, notes, and snippets.

@sei-dupdyke
Created May 20, 2021 20:54
Show Gist options
  • Save sei-dupdyke/f24e966a36aa84c8d43717160e578d91 to your computer and use it in GitHub Desktop.
Save sei-dupdyke/f24e966a36aa84c8d43717160e578d91 to your computer and use it in GitHub Desktop.
Download MM custom emoji
import requests
import json
import os
import shutil
import time
my_mm_server = "some.machine.com"
url = "https://{}/api/v4/emoji".format(my_mm_server)
payload = {}
headers = {
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'DNT': '1',
'Upgrade-Insecure-Requests': '1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-GPC': '1',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document',
'Accept-Language': 'en-US,en;q=0.9',
'Cookie': '<put cookie here>'
}
response = requests.request("GET", url, headers=headers, data=payload)
save_dir = "images"
if not os.path.exists(save_dir):
os.makedirs(save_dir)
for emoji in json.loads(response.text):
id = str(emoji["id"])
image_url = "https://{}/api/v4/emoji/{}/image".format(my_mm_server, id)
print(image_url)
r = requests.get(image_url, stream=True, data=payload, headers=headers)
print(r.status_code)
if r.status_code == 200:
with open(save_dir + '/' + emoji["name"] + '.jpg', 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
# time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment