This commit is contained in:
Freya Murphy 2023-11-02 23:04:31 -04:00
commit b09a9f378d
No known key found for this signature in database
GPG key ID: 988032A5638EE799
2 changed files with 60 additions and 0 deletions

47
export.py Normal file
View file

@ -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()

13
readme.md Normal file
View file

@ -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`