solorpower_crawler/tests/check_missing_dates.py

129 lines
5.0 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
1월 28, 29일 데이터 확인 스크립트
"""
from datetime import datetime
import sys
import os
print("Starting checks...", flush=True)
# Add parent directory to path to import modules
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)
print(f"Current dir: {current_dir}", flush=True)
print(f"Parent dir: {parent_dir}", flush=True)
print(f"Sys path: {sys.path}", flush=True)
try:
from crawlers import nrems, hyundai, kremc, sun_wms, cmsolar
from config import SYSTEM_CONSTANTS
print("Imports successful", flush=True)
except Exception as e:
print(f"Import failed: {e}", flush=True)
import traceback
traceback.print_exc()
sys.exit(1)
def check_dates(plant_config, crawler_module, start_date, end_date):
plant_name = plant_config['name']
print(f"\n[{plant_name}] 데이터 확인: {start_date} ~ {end_date}")
try:
# Check daily data
daily_data = crawler_module.fetch_history_daily(plant_config, start_date, end_date)
if not daily_data:
print(" ❌ 데이터 없음")
return
print(f"{len(daily_data)}일 데이터 수신")
for record in daily_data:
print(f" - 날짜: {record.get('date', 'Unknown')}, 발전량: {record.get('generation_kwh', 0)} kWh")
except Exception as e:
print(f" ❌ 오류 발생: {str(e)}")
# import traceback
# traceback.print_exc()
def main():
print(">>> 1월 28, 29일 데이터 확인 <<<")
# Dates to check
start_date = '2026-01-28'
end_date = '2026-01-29'
test_plants = [
# NREMS 1,2호기 (분리)
({'id': 'nrems-01', 'name': '1호기', 'type': 'nrems',
'auth': {'pscode': 'duce2023072288'},
'options': {'is_split': True, 'unit_id': 1},
'system': SYSTEM_CONSTANTS['nrems']}, nrems),
({'id': 'nrems-02', 'name': '2호기', 'type': 'nrems',
'auth': {'pscode': 'duce2023072288'},
'options': {'is_split': True, 'unit_id': 2},
'system': SYSTEM_CONSTANTS['nrems']}, nrems),
# NREMS 3호기
({'id': 'nrems-03', 'name': '3호기', 'type': 'nrems',
'auth': {'pscode': 'dc2023121086'},
'options': {},
'system': SYSTEM_CONSTANTS['nrems']}, nrems),
# NREMS 4호기
({'id': 'nrems-04', 'name': '4호기', 'type': 'nrems',
'auth': {'pscode': 'duce2023072269'},
'options': {},
'system': SYSTEM_CONSTANTS['nrems']}, nrems),
# NREMS 9호기
({'id': 'nrems-09', 'name': '9호기', 'type': 'nrems',
'auth': {'pscode': 'a2020061008'},
'options': {},
'system': SYSTEM_CONSTANTS['nrems']}, nrems),
# KREMC 5호기
({'id': 'kremc-05', 'name': '5호기', 'type': 'kremc',
'auth': {'user_id': '서대문도서관', 'password': 'sunhope5!'},
'options': {'cid': '10013000376', 'cityProvCode': '11', 'rgnCode': '11410',
'dongCode': '1141011700', 'enso_type_code': '15001'},
'system': SYSTEM_CONSTANTS['kremc']}, kremc),
# Sun-WMS 6호기
({'id': 'sunwms-06', 'name': '6호기', 'type': 'sun_wms',
'auth': {'payload_id': 'kc0fXUW0LUm2wZa+2NQI0Q==', 'payload_pw': 'PGXjU6ib2mKYwtrh2i3fIQ=='},
'options': {},
'system': SYSTEM_CONSTANTS['sun_wms']}, sun_wms),
# Hyundai 8호기
({'id': 'hyundai-08', 'name': '8호기', 'type': 'hyundai',
'auth': {'user_id': 'epecoop', 'password': 'sunhope0419', 'site_id': 'M0494'},
'options': {},
'system': SYSTEM_CONSTANTS['hyundai']}, hyundai),
# CMSolar 10호기 (Fix login info from verify_data.py if valid, otherwise use config.py's)
# Using config.py's info but updated with values seen in verify_data.py which seemed to be used for testing
# verify_data.py had: 'login_id': 'smart3131', 'password': 'ehdrb!123'
# config.py has: 'login_id': 'sy7144', 'login_pw': 'sy7144'
# I should probably use what is in config.py OR verify_data.py. Let's try config.py first as it is the source of truth usually,
# BUT wait, verify_data.py was likely used recently.
# Let's check config.py again. Config.py has 'sy7144'. verify_data.py has 'smart3131'.
# The user history mentioned "Debugging Real-time Crawlers" and "CMSolar".
# Let's check `crawler/crawlers/cmsolar.py` to see what it expects or if there are hardcoded overrides.
({'id': 'cmsolar-10', 'name': '10호기', 'type': 'cmsolar',
'auth': {'login_id': 'sy7144', 'login_pw': 'sy7144', 'site_no': '834'},
'options': {},
'system': SYSTEM_CONSTANTS['cmsolar']}, cmsolar),
]
for plant_config, crawler_module in test_plants:
check_dates(plant_config, crawler_module, start_date, end_date)
if __name__ == '__main__':
main()