-
Notifications
You must be signed in to change notification settings - Fork 8
/
taexin_parse.py
executable file
·38 lines (36 loc) · 1.11 KB
/
taexin_parse.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
#!/usr/bin/env python
import glob
import os,sys
import re
input=sys.argv[1]
f=None
for line in open(input,encoding="utf-8-sig"):
line = line.strip().replace("~","~")
if not line: continue
gs = re.findall('^【(.+)】(.+)$',line)[::-1]
if len(gs) == 1:
#print(gs)
if f:
#print(file=f)
f.close()
line=gs[0][1].strip()
py=re.findall('^[a-z1-8-/ ]*',line)[0]
line=line[len(py):].strip()
py=py.strip()
fname=re.sub("[/-][a-z1-8]+", "", py)
fname=re.sub("[^a-z1-8]+", "_", fname)
fname=re.sub("(.*?)", "", fname)
fname=re.sub("\d","",fname)
fname = fname.rstrip("_")
fname=os.path.join(fname[0],fname+".md")
exist = os.path.exists(fname)
#print(fname)
f=open(fname, mode="a",encoding="U8")
if exist:
print(file=f)
print("# %s\n%s\n> 泰县方言志" % (gs[0][0], py),file=f)
if line:
line=re.sub("(\d)","\n- ",line.strip()).strip("\n- ")
print("-", line,file=f)
else:
print(line, "解析失败")