# -*- coding: utf-8 -*- import openpyxl, glob, os, shutil, zipfile BASE=os.path.dirname(os.path.abspath(__file__)) # 작업파일\공공기관 ROOT=os.path.dirname(BASE) # 작업파일 DATE='2026-06-14' pkgdir=os.path.join(ROOT,'제출폴더','_제출패키지_'+DATE) subdir=os.path.join(pkgdir,'제출_프리랜서2_'+DATE) os.makedirs(subdir, exist_ok=True) board=openpyxl.load_workbook(os.path.join(BASE,'공공기관_작업현황.xlsx')).active hdr={board.cell(1,c).value:c for c in range(1,board.max_column+1)} targets=[] for r in range(2,board.max_row+1): g=board.cell(r,hdr['기관']).value if not g: continue if board.cell(r,hdr['검수']).value=='완료' and '미완료' in str(board.cell(r,hdr.get('제출완료',9)).value): targets.append((board.cell(r,hdr['번호']).value, str(g).strip())) def findfile(no,name): for d in glob.glob(os.path.join(BASE,'*')): b=os.path.basename(d) if os.path.isdir(d) and b.startswith(str(no)+'.'): xs=[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)] if xs: return xs[0] return None copied=[] for no,name in sorted(targets,key=lambda x:x[0]): xp=findfile(no,name) if not xp: print(' 파일없음 %s.%s'%(no,name)); continue dst=os.path.join(subdir, os.path.basename(xp)) shutil.copy2(xp, dst) copied.append((no,name,os.path.basename(xp))) print('복사 %d개 -> %s'%(len(copied), subdir)) for no,name,f in copied: print(' %s.%s : %s'%(no,name,f)) # zip zp=os.path.join(pkgdir,'제출_프리랜서2_'+DATE+'.zip') with zipfile.ZipFile(zp,'w',zipfile.ZIP_DEFLATED) as z: for no,name,f in copied: z.write(os.path.join(subdir,f), arcname='제출_프리랜서2_'+DATE+'/'+f) print('zip 생성:', zp, '(%d KB)'%(os.path.getsize(zp)//1024))