Skip to content

Commit

Permalink
refactor: narrow down payload types
Browse files Browse the repository at this point in the history
  • Loading branch information
kruschk committed Oct 20, 2023
1 parent 21d44a5 commit 1f2394a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parsers/CA_SK.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def fetch_production(
logger: Logger = getLogger(__name__),
) -> list[dict[str, Any]]:
payload = _request(session, target_datetime, PRODUCTION_URL, zone_key)
if not isinstance(payload, dict):
raise ParserException("CA_SK.py", "Unexpected payload type", zone_key)
# Date is in the format "Jan 01, 2020"
date = datetime.strptime(payload["SupplyDataText"], "%b %d, %Y")
production_mix = ProductionMix()
Expand Down Expand Up @@ -96,6 +98,8 @@ def fetch_consumption(
logger: Logger = getLogger(__name__),
) -> list[dict[str, Any]]:
payload = _request(session, target_datetime, CONSUMPTION_URL, zone_key)
if not isinstance(payload, str):
raise ParserException("CA_SK.py", "Unexpected payload type", zone_key)
# The source refreshes every 5 minutes, so we assume the current data is
# from 5 minutes before the most recent multiple of 5 minutes.
now = datetime.now(TIMEZONE)
Expand Down

0 comments on commit 1f2394a

Please sign in to comment.