-
Notifications
You must be signed in to change notification settings - Fork 3
/
generator.py
36 lines (29 loc) · 1.01 KB
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
import sys
import plistlib
from pypinyin import lazy_pinyin
from jinja2 import Environment, FileSystemLoader
def get_readings(word, data):
if 'readings' in data:
return ''.join(i for i in data['readings'][0] if not i.isdigit())
else:
return ''.join(lazy_pinyin(word))
def main():
if len(sys.argv) > 1:
path = sys.argv[1]
emoji = plistlib.readPlist(path)
words = {}
template_name = 'template.lua'
env = Environment(loader=FileSystemLoader("./"), trim_blocks=True)
template = env.get_template(template_name)
for word, data in emoji.items():
reading = get_readings(word, data)
if reading not in words:
words[reading] = set()
words[reading] = words[reading] | set(data['emoji'])
with open('emoji.lua', 'w') as f:
f.write(template.render(words=words))
else:
print('Please input path to emoji plist.')
if __name__ == '__main__':
main()