37769-vm/fix_redundancy.py
2026-05-30 08:01:02 +00:00

37 lines
880 B
Python

import sys
file_path = 'core/views.py'
with open(file_path, 'r') as f:
lines = f.readlines()
new_lines = []
seen_keys = set()
current_dict = False
for line in lines:
if '{' in line:
current_dict = True
seen_keys = set()
new_lines.append(line)
continue
if '}' in line:
current_dict = False
new_lines.append(line)
continue
if current_dict:
match = re.search(r"'([^']+)':", line)
if match:
key = match.group(1)
if key in seen_keys:
if key in ['sign_types', 'has_large_request', 'has_large_sign']:
continue # Skip redundant keys
seen_keys.add(key)
new_lines.append(line)
import re # needed in the loop above but imported here for the script
with open(file_path, 'w') as f:
f.write("".join(new_lines))