aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAda Isopods <me@bathynomus.xyz>2024-04-03 01:41:15 -0600
committerAda Isopods <me@bathynomus.xyz>2026-10-21 23:27:37 -0600
commit82939c664fcd079a6a1726ac17e6df456eb14423 (patch)
treeab2dd4013a157a204cc1aae9e2d4828e4613d06b
parentf3b8839feab4f8406fece1d350fb72a3b38bdb5f (diff)
Add the code
-rw-r--r--README.md9
-rwxr-xr-xgen.py38
2 files changed, 45 insertions, 2 deletions
diff --git a/README.md b/README.md
index d6e063b..b642298 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,8 @@
-# key-emojipack-generator
+Janky Python script to generate the requisite meta.json file to make an emoji pack that can be imported by a *key instance.
-Procedurally generate a meta.json file for importing a folder of emojis on a *key instance \ No newline at end of file
+# Usage
+
+Provide the script with a directory and it will generate a meta.json file listing every PNG/JPG/GIF/WEBP file, extrapolating the emoji name from the filename, and the category name from the directory name.
+
+- Pass `--host` to optionally customize the hostname used as the `host` property.
+- Pass `-p` to print the JSON to stdout instead of saving it. \ No newline at end of file
diff --git a/gen.py b/gen.py
new file mode 100755
index 0000000..26bff36
--- /dev/null
+++ b/gen.py
@@ -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