Add the code
This commit is contained in:
parent
3d43669659
commit
d90322656c
2 changed files with 45 additions and 2 deletions
|
@ -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
|
||||
# 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.
|
38
gen.py
Executable file
38
gen.py
Executable file
|
@ -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)
|
Loading…
Reference in a new issue