파일 주석 추가, 파일 형식 처리 추가
This commit is contained in:
@ -1,3 +1,13 @@
|
|||||||
|
# POS Update
|
||||||
|
'''
|
||||||
|
포스 데이터를 추출한 엑셀파일을 업데이트
|
||||||
|
OK포스 > 매출관리 > 일자별 > 상품별 > 날짜 지정 > 조회줄수 5000으로 변경 > 엑셀
|
||||||
|
추출파일을 ./data에 복사
|
||||||
|
본 파일 실행하면 자동으로 mariadb의 DB에 삽입함.
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
import sys, os
|
import sys, os
|
||||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
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()
|
CONFIG = load_config()
|
||||||
DATA_DIR = os.path.join(os.path.dirname(__file__), '../data')
|
DATA_DIR = os.path.join(os.path.dirname(__file__), '../data')
|
||||||
|
|
||||||
|
|
||||||
def update_pos_table(engine, table, df):
|
def update_pos_table(engine, table, df):
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
for idx, row in df.iterrows():
|
for idx, row in df.iterrows():
|
||||||
@ -37,11 +46,18 @@ def update_pos_table(engine, table, df):
|
|||||||
|
|
||||||
print("[DONE] 모든 데이터 삽입 완료")
|
print("[DONE] 모든 데이터 삽입 완료")
|
||||||
|
|
||||||
|
|
||||||
def process_file(filepath, table, engine):
|
def process_file(filepath, table, engine):
|
||||||
print(f"[INFO] 처리 시작: {filepath}")
|
print(f"[INFO] 처리 시작: {filepath}")
|
||||||
try:
|
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 = df[df.iloc[:, 0] != '합계']
|
||||||
|
|
||||||
df.rename(columns={
|
df.rename(columns={
|
||||||
@ -80,7 +96,6 @@ def process_file(filepath, table, engine):
|
|||||||
print(f"[INFO] 처리 완료: {filepath}")
|
print(f"[INFO] 처리 완료: {filepath}")
|
||||||
return True, len(df)
|
return True, len(df)
|
||||||
|
|
||||||
|
|
||||||
def batch_process_files(table, engine):
|
def batch_process_files(table, engine):
|
||||||
files = [f for f in os.listdir(DATA_DIR) if f.startswith("일자별 (상품별)") and f.endswith(('.xlsx', '.xls'))]
|
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}")
|
print(f"[INFO] 삭제된 파일 수: {deleted_files}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def run_pos_update():
|
def run_pos_update():
|
||||||
filepath = filedialog.askopenfilename(
|
filepath = filedialog.askopenfilename(
|
||||||
filetypes=[("Excel Files", "*.xlsx *.xls")],
|
filetypes=[("Excel Files", "*.xlsx *.xls")],
|
||||||
@ -130,7 +144,6 @@ def run_pos_update():
|
|||||||
print(f"[INFO] 수동 선택된 파일 처리 완료: {count}건")
|
print(f"[INFO] 수동 선택된 파일 처리 완료: {count}건")
|
||||||
messagebox.showinfo("완료", f"DB 업데이트가 완료되었습니다.\n총 {count}건 처리됨.")
|
messagebox.showinfo("완료", f"DB 업데이트가 완료되었습니다.\n총 {count}건 처리됨.")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
engine = db.engine
|
engine = db.engine
|
||||||
try:
|
try:
|
||||||
@ -154,6 +167,5 @@ def main():
|
|||||||
|
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user