summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2023-11-02 23:04:31 -0400
committerFreya Murphy <freya@freyacat.org>2023-11-02 23:04:31 -0400
commitb09a9f378d5e3baa89268559cbae175c0dbcf48a (patch)
tree6c3653b01154fd28711232ec9781e9bb202502e2
downloadmastodon-emoji-exporter-b09a9f378d5e3baa89268559cbae175c0dbcf48a.tar.gz
mastodon-emoji-exporter-b09a9f378d5e3baa89268559cbae175c0dbcf48a.tar.bz2
mastodon-emoji-exporter-b09a9f378d5e3baa89268559cbae175c0dbcf48a.zip
scriptHEADmain
-rw-r--r--export.py47
-rw-r--r--readme.md13
2 files changed, 60 insertions, 0 deletions
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 <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()
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 <server domain>`
+
+`<server domain>` 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`