#!/usr/bin/env python3
"""Fix remaining mapping issues"""
import sys

PATH = '/root/gov_crawler/fix_crawler_naming.py'

with open(PATH, 'r') as f:
    content = f.read()

changes = 0

# 1. Add jiangyou pinyin mapping
if '"jiangyou"' not in content:
    old = '    "江油": "四川",'
    new = '    "江油": "四川",\n    "jiangyou": "四川",'
    if old in content:
        content = content.replace(old, new, 1)
        changes += 1
        print("Added jiangyou pinyin mapping")
    else:
        print("WARNING: '江油' line not found!")

# 2. Add "广州" -> "广东"
if '"广州"' not in content:
    old = '    "佛山": "广东",'
    new = '    "广州": "广东",\n    "佛山": "广东",'
    if old in content:
        content = content.replace(old, new, 1)
        changes += 1
        print("Added 广州 mapping")
    else:
        print("WARNING: '佛山' line not found!")

# 3. Check "舟山"
if '"舟山"' not in content:
    old = '    "仙游": "福建",'
    new = '    "仙游": "福建",\n    "舟山": "浙江",'
    if old in content:
        content = content.replace(old, new, 1)
        changes += 1
        print("Added 舟山 mapping")
    else:
        print("WARNING: '仙游' line not found!")

if changes > 0:
    with open(PATH, 'w') as f:
        f.write(content)
    print(f"Applied {changes} changes")
else:
    print("No changes needed")
