Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6135 Remove Arrow Usage from CA_AB #6559

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions parsers/CA_AB.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from datetime import datetime
from logging import Logger, getLogger
from typing import Any
from zoneinfo import ZoneInfo

# Third-party library imports
import arrow
from requests import Session

from electricitymap.contrib.lib.models.event_lists import ExchangeList, PriceList
Expand All @@ -24,7 +24,7 @@

DEFAULT_ZONE_KEY = ZoneKey("CA-AB")
MINIMUM_PRODUCTION_THRESHOLD = 10 # MW
TIMEZONE = "Canada/Mountain"
TIMEZONE = ZoneInfo("Canada/Mountain")
URL = urllib.parse.urlsplit("http://ets.aeso.ca/ets_web/ip/Market/Reports")
URL_STRING = urllib.parse.urlunsplit(URL)

Expand Down Expand Up @@ -79,9 +79,12 @@ def fetch_price(
prices = PriceList(logger)
for row in csv.reader(response.text.split("\r\n\r\n")[2].splitlines()[1:]):
if row[1] != "-":
date, hour = row[0].split()
prices.append(
zoneKey=zone_key,
datetime=arrow.get(row[0], "MM/DD/YYYY HH", tzinfo=TIMEZONE).datetime,
datetime=datetime.strptime(
f"{date} {int(hour) - 1}", "%m/%d/%Y %H"
).replace(tzinfo=TIMEZONE),
nboswell216 marked this conversation as resolved.
Show resolved Hide resolved
price=float(row[1]),
source=URL.netloc,
currency="CAD",
Expand Down Expand Up @@ -145,11 +148,9 @@ def fetch_production(

def get_csd_report_timestamp(report):
"""Get the timestamp from a current supply/demand (CSD) report."""
return arrow.get(
re.search(r'"Last Update : (.*)"', report).group(1),
"MMM DD, YYYY HH:mm",
tzinfo=TIMEZONE,
).datetime
return datetime.strptime(
re.search(r'"Last Update : (.*)"', report).group(1), "%b %d, %Y %H:%M"
).replace(tzinfo=TIMEZONE)


if __name__ == "__main__":
Expand Down