|
a |
|
b/docs/emojize.py |
|
|
1 |
""" |
|
|
2 |
Small script to emojize html files. |
|
|
3 |
|
|
|
4 |
Inspired by: https://bitbucket.org/lbesson/bin/src/master/emojize.py |
|
|
5 |
""" |
|
|
6 |
|
|
|
7 |
import glob |
|
|
8 |
import re |
|
|
9 |
from sys import argv |
|
|
10 |
|
|
|
11 |
from emoji import emojize |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
def match_to_emoji(m: re.Match) -> str: |
|
|
15 |
return emojize(m.group(), language="alias") |
|
|
16 |
|
|
|
17 |
|
|
|
18 |
def emojize_all(s: str) -> str: |
|
|
19 |
return re.sub(r":([0-9a-z_-]+):", match_to_emoji, s) |
|
|
20 |
|
|
|
21 |
|
|
|
22 |
if __name__ == "__main__": |
|
|
23 |
|
|
|
24 |
dir = argv[1] |
|
|
25 |
|
|
|
26 |
for file in glob.glob(dir + "/*.html"): |
|
|
27 |
|
|
|
28 |
with open(file, "r") as f: |
|
|
29 |
html = f.readlines() |
|
|
30 |
|
|
|
31 |
html = [emojize_all(line) for line in html] |
|
|
32 |
|
|
|
33 |
with open(file, "w") as f: |
|
|
34 |
f.write("".join(html)) |