DB_JOB/작업파일/완료/공공기관/_gugak_L_verify.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

41 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# 국악방송(27) L(페이지/게시판) 정확성 검증. 게시판신호(p.total/페이징/리스트) vs 현재 L 불일치 보고.
import openpyxl, glob, os, re, urllib.request, ssl, http.cookiejar, time
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
cj=http.cookiejar.CookieJar(); op=urllib.request.build_opener(urllib.request.HTTPSHandler(context=ctx),urllib.request.HTTPCookieProcessor(cj))
op.addheaders=[('User-Agent','Mozilla/5.0')]
def fixdom(u): return str(u).replace('https://new.igbf.kr','http://www.igbf.kr').replace('http://new.igbf.kr','http://www.igbf.kr')
def g(u):
try: return op.open(fixdom(u),timeout=20).read().decode('utf-8','replace')
except: return ''
TOT=re.compile(r'class="total"[^>]*>.*?\((\d+)\)',re.S)
DIR=os.path.dirname(os.path.abspath(__file__))
d=[x for x in glob.glob(os.path.join(DIR,'27.*')) if os.path.isdir(x)][0]
xp=[p for p in glob.glob(os.path.join(d,'*.xlsx')) if not os.path.basename(p).startswith(('_','~')) and 'conflict' not in os.path.basename(p) and 'backup' not in p][0]
ws=openpyxl.load_workbook(xp).active
def eff(r,c):
v=ws.cell(r,c).value
if v is not None: return v
for mr in ws.merged_cells.ranges:
if mr.min_col==c and mr.min_row<=r<=mr.max_row: return ws.cell(mr.min_row,c).value
return None
data=[r for r in range(3,ws.max_row+1) if ws.cell(r,2).value is not None]
# 라디오프로그램보드는 이미 검증됨 → 제외, 나머지 igbf 페이지/게시판만
mism=[]
for r in data:
u=str(ws.cell(r,11).value or ''); L=ws.cell(r,12).value
if 'radio_program_board.jsp' in u: continue
if L=='사이트' or 'igbf.kr' not in u or 'http' not in u: continue
h=g(u)
if not h: continue
tot=TOT.search(h)
# 게시판신호: p.total 또는 다건 리스트(view링크 다수) 또는 페이징
board_sig = bool(tot) or len(re.findall(r'state=view',h))>=3 or len(re.findall(r'[?&]idx=\d+',h))>=3 or bool(re.search(r'doListSearch|board_list|pageIndex|goPage|viewRecordInfo',h))
want = '게시판' if board_sig else '페이지'
if L!='사이트' and L!=want:
mism.append((r,eff(r,4),eff(r,5),ws.cell(r,6).value,L,want, tot.group(1) if tot else ''))
time.sleep(0.02)
print('L 불일치 %d행:'%len(mism))
for r,D,E,F,cur,want,tt in mism: print(' r%d [%s>%s>%s] 현재=%s 신호=%s total=%s | %s'%(r,D or '',E or '',F or '',cur,want,tt,str(ws.cell(r,11).value)[-26:]))
print('DONE')