-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_html.py
40 lines (30 loc) · 966 Bytes
/
process_html.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
39
40
import sys
import glob
import re
def simplify_credits(html):
"""
Replace the credit part of the HTML footer. Return the new text.
"""
s = r'<a class="muted-link" href="https://pradyunsg\.me">@pradyunsg</a>\'s'
pattern = re.compile(s)
html = pattern.sub(r'', html)
s = r'Copyright © 2022, Agile Scientific'
pattern = re.compile(s)
new_s = '© 2022, Agile Scientific | <a href="https://creativecommons.org/licenses/by/4.0/">CC BY</a>'
html = pattern.sub(new_s, html)
return html
def main(path):
"""
Process the HTML files in path, save in place (side-effect).
"""
fnames = glob.glob(path.strip('/') + '/*.html')
for fname in fnames:
with open(fname, 'r+') as f:
html = f.read()
new_html = simplify_credits(html)
f.seek(0)
f.write(new_html)
f.truncate()
return
if __name__ == '__main__':
_ = main(sys.argv[1])