#!/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)