-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_templates.py
More file actions
55 lines (46 loc) · 1.59 KB
/
update_templates.py
File metadata and controls
55 lines (46 loc) · 1.59 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import re
# Base directory for templates
templates_dir = r"c:\JAY\EPITA\My Projects\Web Dev\Transcript_Website\Student-Transcript-Website-main\templates"
# Patterns to replace
replacements = [
(
r'style="display: flex; justify-content: space-between; width: 100%; align-items: center;"',
'class="navbar-flex"'
),
(
r'style="padding: 16px;"',
'class="breadcrumb-card"'
),
]
def update_file(filepath):
"""Update a single HTML file with the replacements"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
original_content = content
for pattern, replacement in replacements:
content = re.sub(pattern, replacement, content)
# Only write if changes were made
if content != original_content:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
print(f"Updated: {filepath}")
return True
return False
except Exception as e:
print(f"Error processing {filepath}: {e}")
return False
def main():
"""Process all HTML files in templates directory"""
updated_count = 0
# Walk through all subdirectories
for root, dirs, files in os.walk(templates_dir):
for file in files:
if file.endswith('.html'):
filepath = os.path.join(root, file)
if update_file(filepath):
updated_count += 1
print(f"\nTotal files updated: {updated_count}")
if __name__ == "__main__":
main()