파일 주석 추가, 파일 형식 처리 추가
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user