From 085abc38f333b5a981dcffcab52cb350f5cc10aa Mon Sep 17 00:00:00 2001 From: KWON Date: Mon, 21 Jul 2025 17:34:47 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20=ED=8C=8C=EC=9D=BC=20=ED=98=95=EC=8B=9D?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pos_update_gui.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/pos_update_gui.py b/lib/pos_update_gui.py index d02403d..b60dae6 100644 --- a/lib/pos_update_gui.py +++ b/lib/pos_update_gui.py @@ -1,3 +1,13 @@ +# POS Update +''' +포스 데이터를 추출한 엑셀파일을 업데이트 +OK포스 > 매출관리 > 일자별 > 상품별 > 날짜 지정 > 조회줄수 5000으로 변경 > 엑셀 +추출파일을 ./data에 복사 +본 파일 실행하면 자동으로 mariadb의 DB에 삽입함. + +''' + + import sys, os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) @@ -13,7 +23,6 @@ from lib.common import load_config CONFIG = load_config() DATA_DIR = os.path.join(os.path.dirname(__file__), '../data') - def update_pos_table(engine, table, df): with engine.begin() as conn: for idx, row in df.iterrows(): @@ -37,11 +46,18 @@ def update_pos_table(engine, table, df): print("[DONE] 모든 데이터 삽입 완료") - def process_file(filepath, table, engine): print(f"[INFO] 처리 시작: {filepath}") try: - df = pd.read_excel(filepath, header=5) + ext = os.path.splitext(filepath)[-1].lower() + + if ext == ".xls": + df = pd.read_excel(filepath, header=5, engine="xlrd") + elif ext == ".xlsx": + df = pd.read_excel(filepath, header=5, engine="openpyxl") + else: + raise ValueError("지원하지 않는 파일 형식입니다.") + df = df[df.iloc[:, 0] != '합계'] df.rename(columns={ @@ -80,7 +96,6 @@ def process_file(filepath, table, engine): print(f"[INFO] 처리 완료: {filepath}") return True, len(df) - def batch_process_files(table, engine): files = [f for f in os.listdir(DATA_DIR) if f.startswith("일자별 (상품별)") and f.endswith(('.xlsx', '.xls'))] @@ -108,7 +123,6 @@ def batch_process_files(table, engine): print(f"[INFO] 삭제된 파일 수: {deleted_files}") return True - def run_pos_update(): filepath = filedialog.askopenfilename( filetypes=[("Excel Files", "*.xlsx *.xls")], @@ -130,7 +144,6 @@ def run_pos_update(): print(f"[INFO] 수동 선택된 파일 처리 완료: {count}건") messagebox.showinfo("완료", f"DB 업데이트가 완료되었습니다.\n총 {count}건 처리됨.") - def main(): engine = db.engine try: @@ -154,6 +167,5 @@ def main(): root.mainloop() - if __name__ == "__main__": main()