DB_JOB/작업파일/완료/광역_사이트맵/충청북도/_cy2_Lurl.py
hehihoho3 df16c98366 백업: DB수집 전체 스냅샷 (공공기관2 정리 전)
공공기관2 작업 중. _temp 몽타주(재생성가능)는 제외.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 18:15:40 +09:00

46 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
# 청양 123+ L 재판정: 파일 K URL 패턴 기반(신뢰) + 크롤 시그널 보강
import openpyxl, json, io, sys, re
from urllib.parse import urlparse
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
F=r'D:\01.프로젝트\DB수집\작업파일\광역_사이트맵\충청남도\13.청양군\충청남도_청양군.xlsx'
wb=openpyxl.load_workbook(F); ws=wb.active
INTERNAL=('cheongyang.go.kr','cy.go.kr')
def is_int(h): return any(x in (h or '') for x in INTERNAL)
ver=json.load(open('_cy2_Lverdict.json',encoding='utf-8')) if False else {}
rows=[]
for r in range(123,ws.max_row+1):
b=ws.cell(r,2).value
if b is None: continue
hl=ws.cell(r,11).hyperlink
u=(hl.target if hl else ws.cell(r,11).value) or ''
L=ws.cell(r,12).value
lab=str(ws.cell(r,6).value or ws.cell(r,7).value or ws.cell(r,5).value or '')[:18]
rows.append((r,b,lab,str(u),L))
def url_class(u):
host=urlparse(u).netloc.lower()
if u and not u.startswith('http'): return None,'rel'
if u and not is_int(host): return '사이트','ext:'+host
# 게시판 URL 패턴
if re.search(r'selectBoardList\.do|/cop/bbs/BBSMSTR|/bbs/.*list|selectBbsNttList', u): return '게시판','bbs'
if re.search(r'/prog/.+/list\.do', u): return '게시판','prog-list'
return None,'kor' # /kor/subNN.do 등은 크롤필요
cnt={}
out=[]
for r,b,lab,u,L in rows:
c,why=url_class(u)
out.append((r,b,lab,u,L,c,why))
flag = '' if (c is None or c==L) else (' <<<DIFF(현재%s%s)'%(L,c))
if c and c!=L:
cnt[(L,c)]=cnt.get((L,c),0)+1
print('=== URL패턴으로 확정되는 행 중 현재L과 불일치 ===')
for r,b,lab,u,L,c,why in out:
if c and c!=L:
print('r%d B%s %-18s 현재=%s%s [%s] %s'%(r,b,lab,L,c,why,u[:60]))
print('\n불일치 요약',cnt)
print('URL로 확정안되는(kor .do, 크롤필요) 행수:',sum(1 for o in out if o[5] is None and o[6]=='kor'))
json.dump([{'r':r,'b':b,'lab':lab,'u':u,'L':L,'urlc':c,'why':why} for r,b,lab,u,L,c,why in out],
open('_cy2_Lurl.json','w',encoding='utf-8'),ensure_ascii=False)