solorpower/crawler/tests/debug_kremc.py
haneulai e9a4f8e401 Add 'crawler/' from commit 'c9ed91d885f3c46efb98e98310a1882bb5936546'
git-subtree-dir: crawler
git-subtree-mainline: 8991b92ac8
git-subtree-split: c9ed91d885
2026-06-15 12:53:36 +09:00

44 lines
1.2 KiB
Python

import requests
from dotenv import load_dotenv
load_dotenv()
from config import get_all_plants
from crawlers.kremc import fetch_data
from crawlers.base import create_session
def debug_kremc():
plants = get_all_plants()
# 5호기 (kremc) 찾기 - id가 kremc-05인 것
target = next((p for p in plants if p['id'] == 'kremc-05'), None)
if not target:
print("Plant kremc-05 not found")
return
print(f"Debug target: {target['name']}")
print(f"Debug target: {target['name']}")
from datetime import datetime
today = datetime.now().strftime('%Y-%m-%d')
print(f"Fetching hourly history for {today}...")
from crawlers.kremc import fetch_history_hourly
from database import save_history
try:
results = fetch_history_hourly(target, today, today)
print(f"Hourly Results ({len(results)}):")
for r in results:
print(f" {r['timestamp']}: {r['generation_kwh']} kWh")
if results:
print("Saving to DB...")
save_history(results, 'hourly')
print("Done.")
except Exception as e:
print(f"Exception: {e}")
if __name__ == "__main__":
debug_kremc()