Skip to content

Commit

Permalink
refactor: provide a Session default argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kruschk committed Oct 18, 2023
1 parent b8cd3a6 commit c20e9c1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions parsers/CA_SK.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


def _request(
session: Session | None,
session: Session,
target_datetime: datetime | None,
url: str,
zone_key: ZoneKey,
Expand All @@ -44,7 +44,6 @@ def _request(
# The zone key must be "CA-SK"; bail out otherwise.
if zone_key != "CA-SK":
raise ParserException("CA_SK.py", f"Cannot parse zone '{zone_key}'", zone_key)
session = session or Session()
# Mimic a user browser in the headers or the API will respond with a 403.
response = session.get(url, headers={"user-agent": USER_AGENT})
if not response.ok:
Expand All @@ -59,7 +58,7 @@ def _request(

def fetch_production(
zone_key: ZoneKey = ZoneKey("CA-SK"),
session: Session | None = None,
session: Session = Session(),
target_datetime: datetime | None = None,
logger: Logger = getLogger(__name__),
) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -88,7 +87,7 @@ def fetch_production(

def fetch_consumption(
zone_key: ZoneKey = ZoneKey("CA-SK"),
session: Session | None = None,
session: Session = Session(),
target_datetime: datetime | None = None,
logger: Logger = getLogger(__name__),
) -> dict[str, Any]:
Expand Down

0 comments on commit c20e9c1

Please sign in to comment.