Skip to content

Instantly share code, notes, and snippets.

@akionsight
Created January 25, 2021 03:21
Show Gist options
  • Save akionsight/5d77d2a5f0ae9560e7e34e4f59f22b0b to your computer and use it in GitHub Desktop.
Save akionsight/5d77d2a5f0ae9560e7e34e4f59f22b0b to your computer and use it in GitHub Desktop.
A script to download all the emojis from the Github REST API
import requests
import os
import json
def download_emojis(FOLDER_PATH, EMOJIS_URL, flag=None):
'''
download images from the Github Emojis API
'''
try:
os.mkdir(FOLDER_PATH)
except FileExistsError:
if flag == 'v':
print(f'a folder name {FOLDER_PATH} exists, overwriting file')
emojis = requests.get(EMOJIS_URL).json()
for emoji in emojis.keys():
if os.path.exists(FOLDER_PATH + '\\' + emoji):
print(emoji)
continue
if flag == None:
file = open(FOLDER_PATH + "\\" + emoji + '.png', 'wb')
file.write(requests.get(emojis[emoji]).content)
file.close()
print(emoji)
if flag == 'v':
file = open(FOLDER_PATH + "\\" + emoji + '.png', 'wb')
print(f'file opened for emoji :- {emoji}')
con = requests.get(emojis[emoji]).content
print('requesting server for emoji')
file.write(con)
print('writing to emoji file')
file.close()
print('closing file, saving')
print('\n ---x--- \n')
if flag == 'q':
file = open(FOLDER_PATH + "\\" + emoji + '.png', 'wb')
file.write(requests.get(emojis[emoji]).content)
file.close()
if __name__ == "__main__":
FOLDER = 'emojis' ## enter you folder here
EMOJIS_URL = 'https://api.github.com/emojis' ## you might change this, but it might not work then
download_emojis(FOLDER, EMOJIS_URL, flag=None) ## the flags available are verbose('v') and quiet('q') the normal mode is selected by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment