"""Find how Chungnam cities are categorized in the master file."""
import openpyxl
from pathlib import Path

ROOT = Path(r'D:\01.프로젝트\DB수집')
XLSX = ROOT / '붙임1_공공저작물 개방 대상기관(1160개) 실태조사 목록(신유형개방지원사업) 양식_260518.xlsx'
wb = openpyxl.load_workbook(XLSX, data_only=True)
ws = wb['1단계_홈페이지']

# Known 충청남도 cities to search
targets = ['계룡시', '공주시', '금산군', '논산시', '당진시', '보령시',
           '부여군', '서산시', '서천군', '아산시', '예산군', '천안시',
           '청양군', '태안군', '홍성군']

for name in targets:
    found = False
    for r in range(5, ws.max_row + 1):
        cell_name = ws.cell(row=r, column=4).value
        if cell_name and name in str(cell_name):
            daebun = ws.cell(row=r, column=2).value
            jungbun = ws.cell(row=r, column=3).value
            url = ws.cell(row=r, column=5).value
            print(f'Row {r}: 대={daebun!r} 중={jungbun!r} 기관명={cell_name!r} URL={url!r}')
            found = True
            break
    if not found:
        print(f'NOT FOUND: {name}')
