DB에 저장된 최근 날짜를 출력

This commit is contained in:
2025-10-27 15:07:03 +09:00
parent fa3f7dbe6a
commit 9dab27529d

View File

@ -1,18 +1,26 @@
import time
import os
import os, sys
import threading
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import threading
from sqlalchemy import select, func
# 상위 경로를 sys.path에 추가해 프로젝트 내 모듈 임포트 가능하게 설정
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from conf import db, db_schema
# 처리 스크립트
import pos_update_bill
import pos_update_daily_product
# 데이터 폴더
DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data'))
FILE_EXTENSIONS = ('.xls', '.xlsx')
BILL_PREFIX = "영수증별매출상세현황"
DAILY_PRODUCT_PREFIX = "일자별 (상품별)"
class NewFileHandler(FileSystemEventHandler):
def __init__(self):
super().__init__()
@ -63,6 +71,32 @@ class NewFileHandler(FileSystemEventHandler):
with self._lock:
self._processing_files.discard(filename)
def check_latest_dates():
"""pos 및 pos_billdata 테이블의 최신 일자 조회"""
try:
engine = db.engine
with engine.connect() as conn:
# pos 테이블
pos_latest = conn.execute(
select(func.max(db_schema.pos.c.date))
).scalar()
# pos_billdata 테이블
bill_latest = conn.execute(
select(func.max(db_schema.pos_billdata.c.sale_date))
).scalar()
print("============================================")
print("[DB] 최근 데이터 저장일")
print(f" - pos : {pos_latest if pos_latest else '데이터 없음'}")
print(f" - pos_billdata : {bill_latest if bill_latest else '데이터 없음'}")
print("============================================")
except Exception as e:
print(f"[DB] 최근 날짜 조회 중 오류 발생: {e}")
def start_watching():
print(f"[WATCHER] '{DATA_DIR}' 폴더 감시 시작")
event_handler = NewFileHandler()
@ -77,5 +111,7 @@ def start_watching():
observer.stop()
observer.join()
if __name__ == "__main__":
check_latest_dates() # ✅ 감시 시작 전 DB의 최신 날짜 출력
start_watching()