diff options
| author | Ada Isopods <me@bathynomus.xyz> | 2024-04-03 01:41:15 -0600 |
|---|---|---|
| committer | Ada Isopods <me@bathynomus.xyz> | 2026-10-21 23:27:37 -0600 |
| commit | 82939c664fcd079a6a1726ac17e6df456eb14423 (patch) | |
| tree | ab2dd4013a157a204cc1aae9e2d4828e4613d06b /gen.py | |
| parent | f3b8839feab4f8406fece1d350fb72a3b38bdb5f (diff) | |
Add the code
Diffstat (limited to 'gen.py')
| -rwxr-xr-x | gen.py | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,38 @@ +#!/bin/python + +from datetime import datetime +import argparse +import os +import re + +parser = argparse.ArgumentParser(description='procedurally generate a meta.json file for importing a folder of emojis on a *key instance') +parser.add_argument('directory', help='directory to operate on') +parser.add_argument('-t', '--host', help='your instance domain name (e.g. mk.example.com). i don\'t actually know what this does or if it matters', default='isopod.zone') +parser.add_argument('-p', '--print', help='print the json to stdout instead of to a file', action='store_true') + +args = parser.parse_args() + +if(os.path.isdir(args.directory) == False): + raise Exception("Directory " + args.directory + " doesn't exist!") + +path = args.directory + +imagefiles = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and re.search(r"\.(png|apng|jpeg|jpg|gif|webp)$", f)] +names = [str.lower(re.sub(r'^[^a-zA-Z0-9]+|[^a-zA-Z0-9]$', '', re.sub(r'[^a-zA-Z0-9]+', '_', re.sub(r'\..+$', '', f)))) for f in imagefiles] +packname = os.path.basename(os.path.realpath(path)) + +jsonstart = r'{"metaVersion": 2, "host": "' + args.host + r'", "exportedAt": "' + '{:%Y-%m-%dT%H:%M:%SZ}'.format(datetime.now()) + r'", "emojis": [' +jsonend = ']}' + +jsonentries = [] + +for idx, x in enumerate(names): + jsonentries.append(r'{"downloaded": true, "fileName": "' + imagefiles[idx] + r'", "emoji": { "name": "' + x + r'", "category": "' + packname + r'", "aliases": []}}') + +finaljson = jsonstart + '\n' + ',\n'.join(jsonentries) + '\n' + jsonend + +if(args.print): + print(finaljson) +else: + with open(os.path.join(path, 'meta.json'), "w") as text_file: + text_file.write(finaljson)
\ No newline at end of file |
