DB_JOB/작업파일/공공기관2/3.한국조세재정연구원/_kipf_lm.py
hehihoho3 b0acd1e705 백업: 셀병합 정상화(D~J)+KDHC 옵션2/행높이17, 오늘(06-21) 제출 17곳 검수·압축
- 공공기관2/3 작업본 + 오늘 제출 17곳 D~J 카테고리 셀병합 정상화
- 한국지역난방공사 옵션2(고아셀 F98 수정)+전행 높이17
- 제출_프리랜서2_2026-06-21.zip 생성(17개 xlsx, 2,468행)

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

50 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
import openpyxl,ssl,urllib.request,re,time,shutil
from bs4 import BeautifulSoup
ctx=ssl.create_default_context();ctx.check_hostname=False;ctx.verify_mode=ssl.CERT_NONE
HDR={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124 Safari/537.36'}
def fetch(u): return urllib.request.urlopen(urllib.request.Request(u,headers=HDR),timeout=25,context=ctx).read()
TOT1=re.compile(r'\s*게시물\s*(\d[\d,]*)')
TOT2=re.compile(r'전체\s*(\d[\d,]*)\s*건')
TOT3=re.compile(r'(\d[\d,]*)\s*건')
CENTER_SITE=re.compile(r'kipf\.re\.kr/(cpem|soe|gafsc|cfa|projections|ctla|panel|beps|gmac|sesim)/',re.I)
SRC='한국조세재정연구원.xlsx'
shutil.copy(SRC,'한국조세재정연구원_backup_LM전.xlsx')
wb=openpyxl.load_workbook(SRC);ws=wb.active
def getM(u):
try: soup=BeautifulSoup(fetch(u),'html.parser')
except Exception as e: return None,'ERR'
txt=soup.get_text(' ',strip=True)
m=TOT1.search(txt)
if m: return int(m.group(1).replace(',','')),'총게시물'
m=TOT2.search(txt)
if m: return int(m.group(1).replace(',','')),'전체N건'
# first "N 건" but avoid huge year etc -> take first reasonable
m=TOT3.search(txt)
if m: return int(m.group(1).replace(',','')),'N건'
return 0,'none'
site=board=page=0
for r in range(3,ws.max_row+1):
if all(ws.cell(r,c).value in (None,'') for c in range(2,16)): continue
K=str(ws.cell(r,11).value or '');L=ws.cell(r,12).value
if CENTER_SITE.search(K) or 'soelms.kipf.re.kr' in K:
ws.cell(r,12).value='사이트'
for c in (13,14,15,16,17): ws.cell(r,c).value=None
site+=1; continue
if L=='사이트':
site+=1; continue
if L=='게시판':
M,how=getM(K)
ws.cell(r,13).value=M
if M==0: ws.cell(r,14).value='없음'
board+=1
print(f'r{r} {(ws.cell(r,6).value or ws.cell(r,5).value or "")[:18]:18} M={M} ({how})')
time.sleep(0.4)
else:
page+=1
print(f'\n게시판 {board} · 사이트 {site} · 페이지 {page}')
wb.save(SRC); print('saved')