OTE informatin discord
Some checks failed
CI and deploy / migration-check (push) Failing after 25s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-29 14:17:24 +02:00
parent 2eeab58c8e
commit 6074535d96
5 changed files with 348 additions and 1 deletions

View File

@@ -12,7 +12,10 @@ import httpx
from app.config import get_settings
from app.db_json import fetch_json
from services.notification_service import notify_ote_import_format_changed
from services.notification_service import (
notify_ote_import_format_changed,
notify_ote_import_ok_brief,
)
logger = logging.getLogger(__name__)
@@ -154,6 +157,7 @@ async def import_ote_prices_for_day(
stats_after = json.loads(stats_after)
first_price = stats_after.get("first_price")
n_imported = int(stats_after.get("count") or 0)
is_complete = bool(stats_after.get("is_complete"))
if not ote_prague_day_slots_look_complete(n_imported):
logger.warning(
"OTE: %s slotů pro %s (plný den = jedna z %s; jinak neúplná data)",
@@ -161,6 +165,21 @@ async def import_ote_prices_for_day(
day_str,
sorted(OTE_FULL_DAY_SLOT_COUNTS),
)
if is_complete:
brief = await fetch_json(
conn,
"select ems.fn_ote_day_signals_prague($1::date, $2::int)",
target_day,
14,
)
if not isinstance(brief, dict):
brief = json.loads(brief)
await notify_ote_import_ok_brief(
conn,
report_date=day_str,
brief=brief if isinstance(brief, dict) else {},
url=OTE_URL.format(date=day_str),
)
logger.info(
"OTE import OK: %s slotů (upsert) pro %s, první cena %.4f Kč/kWh",
n,
@@ -305,6 +324,7 @@ async def import_ote_prices(
stats_after = json.loads(stats_after)
first_price = stats_after.get("first_price")
n_imported = int(stats_after.get("count") or 0)
is_complete = bool(stats_after.get("is_complete"))
incomplete = not ote_prague_day_slots_look_complete(n_imported or 0)
if incomplete:
now_p = datetime.now(ZoneInfo("Europe/Prague"))
@@ -320,6 +340,21 @@ async def import_ote_prices(
date_str,
sorted(OTE_FULL_DAY_SLOT_COUNTS),
)
if is_complete:
brief = await fetch_json(
db,
"select ems.fn_ote_day_signals_prague($1::date, $2::int)",
target_day,
14,
)
if not isinstance(brief, dict):
brief = json.loads(brief)
await notify_ote_import_ok_brief(
db,
report_date=date_str,
brief=brief if isinstance(brief, dict) else {},
url=OTE_URL.format(date=date_str),
)
logger.info(
"OTE import OK: %s slotů pro %s, první cena %.4f Kč/kWh",
n,