48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
|
import requests
|
||
|
import sys
|
||
|
import tempfile
|
||
|
import warnings
|
||
|
from PIL import Image
|
||
|
import multiprocessing as mp
|
||
|
import os
|
||
|
|
||
|
temp_dir = tempfile.mkdtemp()
|
||
|
|
||
|
warnings.catch_warnings()
|
||
|
warnings.simplefilter("ignore")
|
||
|
|
||
|
def download(emoji):
|
||
|
emoji_shortcode = emoji['shortcode']
|
||
|
emoji_url = emoji['static_url']
|
||
|
file_type = emoji_url.split('.')[-1]
|
||
|
file_name = emoji_shortcode + '.' + file_type
|
||
|
file_path = temp_dir + '/' + file_name
|
||
|
|
||
|
image = requests.get(emoji_url, verify=False).content
|
||
|
file = open(file_path, 'wb')
|
||
|
file.write(image)
|
||
|
file.close()
|
||
|
print('downloaded', file_path)
|
||
|
|
||
|
def main():
|
||
|
argv = sys.argv
|
||
|
if len(argv) != 2:
|
||
|
print('usage: export.py <url>')
|
||
|
return
|
||
|
|
||
|
url = 'https://' + argv[1] + '/api/v1/custom_emojis'
|
||
|
res = requests.get(url, verify=False)
|
||
|
|
||
|
emojies = res.json()
|
||
|
|
||
|
threads = mp.cpu_count()
|
||
|
|
||
|
with mp.Pool(threads) as p:
|
||
|
p.map(download, emojies)
|
||
|
|
||
|
os.system('tar czvf export.tar.gz -C ' + temp_dir + ' . ' + temp_dir)
|
||
|
os.system('rm -fr ' + temp_dir)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|