commit b09a9f378d5e3baa89268559cbae175c0dbcf48a Author: Freya Murphy Date: Thu Nov 2 23:04:31 2023 -0400 script diff --git a/export.py b/export.py new file mode 100644 index 0000000..7a3deca --- /dev/null +++ b/export.py @@ -0,0 +1,47 @@ +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 ') + 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() diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..03b8916 --- /dev/null +++ b/readme.md @@ -0,0 +1,13 @@ +## mastodon emoji exporter + +this python file exports emojis from a mastodon server + +i want emojies + +### usage + +`python3 export.py ` + +`` is the WEB_DOMAIN of the mastodon instance, a.k.a where is *hosted* + +this script creates a `exports.tar.gz` file which then can be used in `tootctl emoji import`