"""충청북도 시·군 목록을 마스터 엑셀에서 추출."""
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단계_홈페이지']

targets = ['괴산군', '단양군', '보은군', '영동군', '옥천군', '음성군',
           '제천시', '증평군', '진천군', '청주시', '충주시']

for name in targets:
    for r in range(5, ws.max_row + 1):
        cell_name = ws.cell(row=r, column=4).value
        if cell_name and ('충청북도' in str(cell_name) or '충북' in str(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}')
            break
    else:
        print(f'NOT FOUND: {name}')
