-
Notifications
You must be signed in to change notification settings - Fork 0
/
formator.py
38 lines (30 loc) · 942 Bytes
/
formator.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
from xpinyin import Pinyin
import re
sentence = ""
with open('content.html') as f:
sentence = f.readline()
cuted = re.split("(,|。)", sentence)[:-1]
p = Pinyin()
with open('output.html', 'w') as f:
f.write("<p>")
for c in cuted:
if not c == "," and not c == "。":
f.write("<ruby>")
for w in c:
if not w == "," and not w == "。":
f.write(w + "<rt>" + p.get_pinyin(w, tone_marks="marks") + "</rt>")
f.write("</ruby>")
else:
f.write(c)
f.write("</p>")
# print("<p>")
# for c in cuted:
# if not c == "," and not c == "。":
# print("<ruby>", end='')
# for w in c:
# if not w == "," and not w == "。":
# print(w + "<rt>" + p.get_pinyin(w, tone_marks="marks") + "</rt>", end="")
# print("</ruby>", end='')
# else:
# print(c, end='')
# print("\n</p>")