-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-tracking.py
More file actions
29 lines (23 loc) · 784 Bytes
/
add-tracking.py
File metadata and controls
29 lines (23 loc) · 784 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
29
#!/usr/bin/env python3
"""Add track.js to all tool pages that don't have it yet."""
import os
import glob
TRACK_TAG = '<script src="/js/track.js"></script>'
tool_dir = '/var/www/web-ceo/tools'
count = 0
for filepath in sorted(glob.glob(os.path.join(tool_dir, '*.html'))):
basename = os.path.basename(filepath)
if basename == 'index.html':
continue
with open(filepath, 'r') as f:
content = f.read()
if '/js/track.js' in content:
continue
# Add before </body>
if '</body>' in content:
content = content.replace('</body>', f'{TRACK_TAG}\n</body>')
with open(filepath, 'w') as f:
f.write(content)
count += 1
print(f' Added tracking to {basename}')
print(f'\nDone. Updated {count} files.')