import os with open('core/views.py', 'r') as f: lines = f.readlines() start_line = -1 end_line = -1 for i, line in enumerate(lines): if 'def log_door_visit(request):' in line: start_line = i if start_line != -1 and 'def door_visit_history(request):' in line: end_line = i break if start_line != -1 and end_line != -1: with open('core_views_log_visit.py', 'r') as f: new_content = f.read() # Ensure there is a newline before door_visit_history if not new_content.endswith('\n'): new_content += '\n' # Prepend indentation to new_content if needed, but it should be top-level def lines[start_line:end_line] = [new_content + '\n'] with open('core/views.py', 'w') as f: f.writelines(lines) print("Successfully patched log_door_visit in core/views.py") else: print(f"Could not find log_door_visit boundaries: {start_line}, {end_line}")