# Precise fix for the syntax error in admin_routes.py

file_path = r'd:\bookbeach\backend\app\routes\admin_routes.py'

# Read the file
with open(file_path, 'r', encoding='utf-8') as f:
    lines = f.readlines()

# Create a new list of lines with the fix
fixed_lines = []

# Process each line
i = 0
while i < len(lines):
    # Check if we're at the problematic area (around line 1560-1562)
    if i == 1558:  # Line 1559 in file (0-indexed)
        # This should be "        import os\n"
        fixed_lines.append(lines[i])
        i += 1
    elif i == 1559:  # Line 1560 in file (0-indexed)
        # This should be a blank line
        fixed_lines.append(lines[i])
        i += 1
    elif i == 1560:  # Line 1561 in file (0-indexed)
        # This is an extra blank line that should be skipped
        print(f"Skipping extra blank line at line {i+1}")
        i += 1
    elif i == 1561:  # Line 1562 in file (0-indexed)
        # This should be the decorator "@admin_bp.route(...)"
        fixed_lines.append(lines[i])
        i += 1
    else:
        fixed_lines.append(lines[i])
        i += 1

# Write the fixed content back
with open(file_path, 'w', encoding='utf-8') as f:
    f.writelines(fixed_lines)

print("Applied precise fix to admin_routes.py")