From 103b0770ac5a11ff0ec3677dffa85a5788bc11e9 Mon Sep 17 00:00:00 2001 From: Jonah Kruschke Date: Wed, 1 Nov 2023 20:09:00 -0600 Subject: [PATCH] refactor: switch to ProductionMix.add_value method Pass data to the ProductionMix object using the add_value method instead of during object instantiaton. Refs: #6011, #6062 --- parsers/CA_YT.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/parsers/CA_YT.py b/parsers/CA_YT.py index 74ebffbf69..d23dfe8ba3 100644 --- a/parsers/CA_YT.py +++ b/parsers/CA_YT.py @@ -7,9 +7,9 @@ from bs4 import BeautifulSoup from requests import Session -from electricitymap.contrib.config import ZoneKey from electricitymap.contrib.lib.models.event_lists import ProductionBreakdownList from electricitymap.contrib.lib.models.events import ProductionMix, StorageMix +from electricitymap.contrib.lib.types import ZoneKey from parsers.lib.exceptions import ParserException SOURCE = "www.yukonenergy.ca" @@ -87,24 +87,28 @@ def _parse_mw(text): hydro_capacity = soup.find("div", class_="avail_hydro") thermal = soup.find("div", class_="load_thermal").div + production_mix = ProductionMix() + production_mix.add_value("coal", 0) + production_mix.add_value("geothermal", 0) + production_mix.add_value( + "hydro", _parse_mw(soup.find("div", class_="load_hydro").div.text) + ) + production_mix.add_value("nuclear", 0) + production_mix.add_value("unknown", _parse_mw(thermal.text) if thermal else 0) + production_breakdowns = ProductionBreakdownList(logger=logger) production_breakdowns.append( datetime=datetime.strptime(f"{date} {time}", "%A, %B %d, %Y %I:%M %p").replace( tzinfo=TIMEZONE ), - production=ProductionMix( - coal=0, - geothermal=0, - hydro=_parse_mw(soup.find("div", class_="load_hydro").div.text), - nuclear=0, - unknown=_parse_mw(thermal.text) if thermal else 0, - ), + production=production_mix, source=SOURCE, storage=StorageMix( hydro=_parse_mw(hydro_capacity.div.text) if hydro_capacity else None ), zoneKey=ZONE_KEY, ) + return production_breakdowns.to_list()