From 02cd8920fca40b2c4682f4b779ab5d66625e9ca1 Mon Sep 17 00:00:00 2001 From: dt215git <86194065+dt215git@users.noreply.github.com> Date: Tue, 24 Oct 2023 12:52:33 +0100 Subject: [PATCH] update strptime to account for new response text (#1355) --- .../source/northlincs_gov_uk.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/northlincs_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/northlincs_gov_uk.py index 3a75a4b73..4863f8d0d 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/northlincs_gov_uk.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/northlincs_gov_uk.py @@ -1,12 +1,13 @@ +import json from datetime import datetime import requests -import json -from bs4 import BeautifulSoup from waste_collection_schedule import Collection # type: ignore[attr-defined] TITLE = "North Lincolnshire Council" -DESCRIPTION = "Source for northlincs.gov.uk services for North Lincolnshire Council, UK." +DESCRIPTION = ( + "Source for northlincs.gov.uk services for North Lincolnshire Council, UK." +) URL = "https://www.northlincs.gov.uk" TEST_CASES = { "Test_001": {"uprn": "100050200824"}, @@ -29,21 +30,24 @@ def __init__(self, uprn): self._uprn = str(uprn) def fetch(self): - r = requests.get(f"https://m.northlincs.gov.uk/bin_collections?no_collections=20&uprn={self._uprn}") + r = requests.get( + f"https://m.northlincs.gov.uk/bin_collections?no_collections=20&uprn={self._uprn}" + ) r.raise_for_status() - r_json = json.loads(r.content.decode('utf-8-sig'))["Collections"] + r_json = json.loads(r.content.decode("utf-8-sig"))["Collections"] entries = [] for collection in r_json: - date = datetime.strptime(collection["CollectionDate"], "%Y-%m-%d").date() + date = datetime.strptime( + collection["CollectionDate"].split(" ")[0], "%Y-%m-%d" + ).date() waste_type = collection["BinCodeDescription"] entries.append( Collection( date=date, t=waste_type, icon=ICON_MAP.get(waste_type), - ) ) return entries