-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathts.py
More file actions
28 lines (23 loc) · 739 Bytes
/
Copy pathts.py
File metadata and controls
28 lines (23 loc) · 739 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
import sys
def main(filename):
if not filename.endswith(".bak"):
raise "need a backup file"
print(filename)
s = ""
with open(filename) as f:
end = False
for line in f:
if line.startswith("## "):
if end:
s += "\n</div>\n</details>\n\n"
end = False
s += line
print(line.replace("##", "-"), end="")
s += "\n<details>\n<summary>答案</summary>\n<div>\n"
end = True
else:
s += line
s += "\n</div>\n</details>\n\n"
with open(filename.strip(".bak"), "w") as f:
f.write(s)
main(sys.argv[1])