Fix: Croydon, UK (#1241)

* fix date issue, md updated, flake8 F601 added

* remove overwritten parameter  and flake8 F601
This commit is contained in:
dt215git
2023-09-07 20:20:09 +01:00
committed by GitHub
parent dbce7c2168
commit 49ec4bde30
2 changed files with 17 additions and 14 deletions

View File

@@ -13,10 +13,6 @@ from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Croydon Council"
DESCRIPTION = "Source for croydon.gov.uk services for Croydon Council, UK."
URL = "https://croydon.gov.uk"
# Website stops responding if repeated queries are made in quick succession.
# Shouldn't be an issue in normal use where 1 query/day is made, but repeated HA restarts might cause the query to fail.
# When testing, it may be worth testing them individually by commenting out two of the test cases.
TEST_CASES = {
"Test_001": {"postcode": "CR0 6LN", "houseID": "64 Coniston Road"},
"Test_002": {"postcode": "SE25 5BU", "houseID": "23B Howard Road"},
@@ -51,13 +47,11 @@ HEADER_COMPONENTS = {
},
"GET": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Mode": "none",
},
"POST": {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Mode": "same-origin",
"X-Requested-With": "XMLHttpRequest",
},
@@ -88,7 +82,6 @@ class Source:
self._houseID = str(houseID)
def fetch(self):
s = requests.Session()
# Get token
@@ -208,14 +201,26 @@ class Source:
entries = []
for pickup in schedule:
# Get the waste type
waste_type = pickup.find_all(
"div", {"class": "fragment_presenter_template_show"}
)[0].text.strip()
waste_date = (
pickup.find("div", {"class": "bin-collection-next"})
.attrs["data-current_value"]
.strip()
)
try: # Get the next collection date
waste_date = (
pickup.find("div", {"class": "bin-collection-next"})
.attrs["data-current_value"]
.strip()
)
except (
AttributeError
): # If it fails, the collection is schedule for today, so look for that date
waste_date = (
pickup.find("div", {"class": "bin-collection-today"})
.attrs["data-current_value"]
.strip()
)
entries.append(
Collection(
date=datetime.strptime(waste_date, "%d/%m/%Y %H:%M").date(),

View File

@@ -34,5 +34,3 @@ waste_collection_schedule:
postcode: "CR0 2EG"
houseID: "23B Howard Road"
```
Note: Croydon website stops responding if repeated queries are made in quick succession. This shouldn't be an issue in normal use where HA is querying once per day, but repeated HA restarts may result in schedules not being returned.