import datetime from database import TradeDB db = TradeDB() tables = [ "target_candidates_history", "ls_candidates_history", "ls_ws_ticks", "ls_ws_candles", "ls_ws_orderbook", "ls_ws_vi", "ws_price_validation", "ws_price_validation_ls", "condition_job_events" ] out = {} try: # TradeDB 내부 래퍼 메서드 사용 (db.conn.execute) actual_tables_raw = db.conn.execute("SHOW TABLES").fetchall() actual_tables = [list(dict(r).values())[0] for r in actual_tables_raw] for t in tables: if t not in actual_tables: out[t] = "테이블 없음" continue try: cols_raw = db.conn.execute(f"SHOW COLUMNS FROM {t}").fetchall() cols = [dict(r)["Field"] for r in cols_raw] time_col = None for c in ["event_time", "timestamp", "insert_time", "created_at", "updated_at"]: if c in cols: time_col = c break if time_col: res = db.conn.execute( f"SELECT COUNT(*) as c FROM {t} WHERE {time_col} >= %s AND {time_col} < %s", ("2026-08-07 00:00:00", "2026-08-08 00:00:00") ).fetchone() count = dict(res)["c"] if res else 0 out[t] = f"{count:,}건" else: res = db.conn.execute(f"SELECT COUNT(*) as c FROM {t}").fetchone() count = dict(res)["c"] if res else 0 out[t] = f"전체 {count:,}건 (시각컬럼 없음)" except Exception as e: out[t] = f"Error: {e}" print("| 데이터 원천 (테이블명) | 오늘(8/7) 누적 수집 건수 | 설명 |") print("|---|---|---|") desc = { "target_candidates_history": "키움 조건검색 유니버스 이력", "ls_candidates_history": "LS증권 조건검색 유니버스 이력", "ls_ws_ticks": "실시간 체결 틱 데이터 (LS)", "ls_ws_candles": "실시간 1분봉 데이터 (LS)", "ls_ws_orderbook": "실시간 호가잔량 데이터 (LS)", "ls_ws_vi": "변동성 완화장치(VI) 발동 이력", "ws_price_validation": "키움(KIS) 호가 검증 로그", "ws_price_validation_ls": "LS증권 호가 검증 로그", "condition_job_events": "조건검색 엔진 상태/장애 로그" } for k, v in out.items(): print(f"| `{k}` | **{v}** | {desc.get(k, '')} |") finally: db.close()