This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
51 lines (45 loc) · 1.68 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import string
_VERSION = '0.4.0'
_GENERATOR = "asoul-sticker project"
def main():
with open('config.json', encoding='utf8') as f:
config = json.load(f)
config['host'] = config['host'].rstrip('/')
with open('asoul-sticker-base.css', encoding='utf8') as f:
css_base = string.Template(f.read())
with open('asoul-sticker-template.css', encoding='utf8') as f:
css_template = string.Template(f.read())
sticker_items = []
class_prefixes = set()
with open('data.txt', encoding='utf8') as f:
for line in [l.strip() for l in f]:
if len(line) == 0 or line[0] == '#':
continue
dir_name, file_name, class_name, alt_name = line.split(' ')
class_prefixes.add(dir_name)
if config['flatten']:
host = config['host']
else:
host = f'{config["host"]}/{dir_name}'
css_item = css_template.substitute(
className=class_name,
host=host,
filename=file_name,
alt=f'[{alt_name}]',
)
sticker_items.append(css_item)
with open('dist/asoul-sticker.css', 'w', encoding='utf8', newline='\n') as f:
selectors = [f'span[class^="{prefix}_"]' for prefix in sorted(class_prefixes)]
f.write(css_base.substitute(
version=_VERSION,
generator=_GENERATOR,
host=config["host"],
height=config['height'],
flatten=str(config['flatten']).lower(),
selectors=',\n'.join(selectors)
))
f.write('\n')
f.write(''.join(sticker_items))
if __name__ == '__main__':
main()