solorpower_crawler/scripts_archive/test_api.py
2026-03-30 13:01:18 +09:00

75 lines
2.3 KiB
Python

"""
API 호출 테스트 - 5호기와 9호기의 2월 25일 시간별 데이터 확인
"""
import requests
import json
def test_api(plant_id, plant_name, date):
url = f"https://solorpower.dadot.net/plants/{plant_id}/stats/today?date={date}"
print(f"\n{'='*70}")
print(f"🔍 [{plant_name}] API 호출: {date}")
print(f"{'='*70}")
print(f"URL: {url}\n")
try:
response = requests.get(url, timeout=10)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Status: {data.get('status')}")
print(f"Plant ID: {data.get('plant_id')}")
print(f"Date: {data.get('date')}")
print(f"Count: {data.get('count')}\n")
hourly_data = data.get('data', [])
# 데이터가 있는 시간대만 출력
has_data_count = 0
print("시간별 데이터 (데이터가 있는 시간만):")
for item in hourly_data:
if item.get('has_data'):
has_data_count += 1
print(f" {item['label']:>4}: current_kw={item['current_kw']:>8.2f}, today_kwh={item['today_kwh']:>8.2f}")
if has_data_count == 0:
print(" ❌ 데이터가 있는 시간대가 없습니다!")
# 전체 응답 출력
print("\n전체 응답:")
print(json.dumps(data, indent=2, ensure_ascii=False))
else:
print(f"\n✅ 총 {has_data_count}개 시간대에 데이터 있음")
else:
print(f"❌ API 호출 실패")
print(response.text)
except Exception as e:
print(f"❌ 에러 발생: {e}")
import traceback
traceback.print_exc()
def main():
print("\n" + "="*70)
print("🌐 API 호출 테스트")
print("="*70)
# 2월 25일 데이터 확인
test_api("kremc-05", "5호기", "2026-02-25")
test_api("nrems-09", "9호기", "2026-02-25")
# 2월 1일도 확인
test_api("kremc-05", "5호기", "2026-02-01")
test_api("nrems-09", "9호기", "2026-02-01")
print("\n" + "="*70)
print("테스트 완료")
print("="*70 + "\n")
if __name__ == "__main__":
main()