-
Notifications
You must be signed in to change notification settings - Fork 200
/
replace_src.py
26 lines (24 loc) · 1.17 KB
/
replace_src.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
import os
files = []
for parent, dirnames, filenames in os.walk("./docs"):
for name in filenames:
if name.endswith(".md"):
cur = os.path.join(parent, name)
files.append(cur)
for name in files:
file = open(name, "r")
replacement = ""
need_replace = False
for line in file:
line = line.strip()
if '<div align="center"> <img src="../imgs' in line or '<div align="center"> <img src="../../imgs' in line or "wardseptember.top" in line:
need_replace = True
line = line.replace('<div align="center"> <img src="../imgs', '<div align="center"> <img src="https://raw.githubusercontent.com/wardseptember/notes/master/imgs')
line = line.replace('<div align="center"> <img src="../../imgs', '<div align="center"> <img src="https://raw.githubusercontent.com/wardseptember/notes/master/imgs')
line = line.replace('http://wardseptember.top', '<div align="center"> <img src="https://raw.githubusercontent.com/wardseptember/notes/master/imgs')
replacement = replacement + line + "\n"
file.close()
if need_replace:
fout = open(name, "w")
fout.write(replacement)
fout.close()