-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_old_logos.py
More file actions
53 lines (44 loc) · 1.43 KB
/
remove_old_logos.py
File metadata and controls
53 lines (44 loc) · 1.43 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
import re
file_path = r"c:\Users\assdr\Desktop\New Project\index.html"
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
# Helper to find matching closing div
def find_div_end(s, start_idx):
count = 1
i = start_idx + 1
while count > 0 and i < len(s):
if s[i:i+4] == '<div':
count += 1
i += 4
elif s[i:i+6] == '</div>':
count -= 1
i += 6
else:
i += 1
return i
start_marker = '<div class="logo-parent-w">'
matches = []
idx = 0
while True:
idx = content.find(start_marker, idx)
if idx == -1:
break
end_idx = find_div_end(content, idx + len(start_marker))
block_content = content[idx:end_idx]
# Check if this block contains old logos
if "Reddot" in block_content or "Deutscher" in block_content or "Made-in-lux" in block_content:
print(f"Found old logo block at {idx}. Mark for deletion.")
matches.append((idx, end_idx))
else:
print(f"Keeping block at {idx} (seems to be new or other).")
idx = end_idx
if matches:
# Delete match. Iterate backwards.
new_content = content
for start, end in reversed(matches):
new_content = new_content[:start] + new_content[end:]
with open(file_path, "w", encoding="utf-8") as f:
f.write(new_content)
print("Deleted old logo blocks.")
else:
print("No old logo blocks found to delete.")