import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) try: from dotenv import load_dotenv load_dotenv() except ImportError: os.environ['SUPABASE_URL'] = 'https://qgelkvfjnhqwuvltmqct.supabase.co' os.environ['SUPABASE_KEY'] = 'sb_secret_BFkr9u1Npu3asKDWTn40tg_Qnn1uKLc' from database import get_supabase_client import sqlite3 from pathlib import Path client = get_supabase_client() if not client: print("Supabase 연결 실패") sys.exit(1) # 1. 오늘 KST 15:00~18:00 = UTC 06:00~09:00 의 nrems-03 solar_logs 조회 print("=" * 60) print("[1] nrems-03 오늘 15:00~18:00 KST (solar_logs)") print("=" * 60) resp = client.table('solar_logs') \ .select('plant_id, current_kw, today_kwh, status, created_at') \ .eq('plant_id', 'nrems-03') \ .gte('created_at', '2026-05-14T06:00:00+00:00') \ .lte('created_at', '2026-05-14T09:30:00+00:00') \ .order('created_at') \ .execute() for row in resp.data: print(f" {row['created_at']} kw={row['current_kw']} today={row['today_kwh']} status={row['status']}") print(f"총 {len(resp.data)}건\n") # 2. daily_stats 오늘 날짜 확인 print("=" * 60) print("[2] daily_stats 오늘 nrems-03") print("=" * 60) resp2 = client.table('daily_stats') \ .select('*') \ .eq('plant_id', 'nrems-03') \ .eq('date', '2026-05-14') \ .execute() for row in resp2.data: print(f" {row}") # 3. alert_history 로컬 DB 확인 print("\n" + "=" * 60) print("[3] 로컬 alert_history (crawler_manager.db)") print("=" * 60) db_path = Path(__file__).parent.parent / "crawler_manager.db" try: with sqlite3.connect(str(db_path)) as conn: cur = conn.cursor() cur.execute("SELECT site_id, alert_status, last_alert_time FROM alert_history WHERE site_id='nrems-03'") row = cur.fetchone() if row: print(f" site_id={row[0]} status={row[1]} last_alert={row[2]}") else: print(" nrems-03 alert_history 없음") except Exception as e: print(f" 로컬 DB 읽기 실패: {e} (서버 DB는 서버에 있음)")