forked from filiptronicek/filiptronicek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodify.py
25 lines (22 loc) · 956 Bytes
/
modify.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
import re
filename = "README.md"
patt = r'<a class="post" href="https:\/\/blog.trnck.dev\/.*\/">.*<\/a>'
def write(title, url, date):
with open(filename, encoding="utf-8") as f:
content = f.readlines()
content = [x for x in content]
replaced = ""
for c in content:
if re.search(patt, c):
print("found")
splitToModify = c.split(re.split(patt, c)[0])[1]
splitToModify = re.sub(r'href="https://blog.trnck.dev/[.*]?"',
f'href="{url}"', splitToModify)
modify = re.sub(r">.*<", f">{str(title)} (published on {date})<",
splitToModify)
replaced += (c.split(splitToModify)[0]).split("<")[0] + modify
replaced = re.sub(r'\"https://blog.trnck.dev/.*\"', f"\"{url}\"", replaced)
else:
replaced += c
with open(filename, "w", encoding="utf-8") as f:
f.write(replaced)