[79668b]: / docs / emojize.py

Download this file

35 lines (20 with data), 652 Bytes

 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
"""
Small script to emojize html files.
Inspired by: https://bitbucket.org/lbesson/bin/src/master/emojize.py
"""
import glob
import re
from sys import argv
from emoji import emojize
def match_to_emoji(m: re.Match) -> str:
return emojize(m.group(), language="alias")
def emojize_all(s: str) -> str:
return re.sub(r":([0-9a-z_-]+):", match_to_emoji, s)
if __name__ == "__main__":
dir = argv[1]
for file in glob.glob(dir + "/*.html"):
with open(file, "r") as f:
html = f.readlines()
html = [emojize_all(line) for line in html]
with open(file, "w") as f:
f.write("".join(html))