mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
Fix: Croydon, UK (#1241)
* fix date issue, md updated, flake8 F601 added * remove overwritten parameter and flake8 F601
This commit is contained in:
@@ -13,10 +13,6 @@ from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
|||||||
TITLE = "Croydon Council"
|
TITLE = "Croydon Council"
|
||||||
DESCRIPTION = "Source for croydon.gov.uk services for Croydon Council, UK."
|
DESCRIPTION = "Source for croydon.gov.uk services for Croydon Council, UK."
|
||||||
URL = "https://croydon.gov.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_CASES = {
|
||||||
"Test_001": {"postcode": "CR0 6LN", "houseID": "64 Coniston Road"},
|
"Test_001": {"postcode": "CR0 6LN", "houseID": "64 Coniston Road"},
|
||||||
"Test_002": {"postcode": "SE25 5BU", "houseID": "23B Howard Road"},
|
"Test_002": {"postcode": "SE25 5BU", "houseID": "23B Howard Road"},
|
||||||
@@ -51,13 +47,11 @@ HEADER_COMPONENTS = {
|
|||||||
},
|
},
|
||||||
"GET": {
|
"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",
|
"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",
|
"Sec-Fetch-Mode": "none",
|
||||||
},
|
},
|
||||||
"POST": {
|
"POST": {
|
||||||
"Accept": "application/json, text/javascript, */*; q=0.01",
|
"Accept": "application/json, text/javascript, */*; q=0.01",
|
||||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
"Sec-Fetch-Mode": "cors",
|
|
||||||
"Sec-Fetch-Mode": "same-origin",
|
"Sec-Fetch-Mode": "same-origin",
|
||||||
"X-Requested-With": "XMLHttpRequest",
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
},
|
},
|
||||||
@@ -88,7 +82,6 @@ class Source:
|
|||||||
self._houseID = str(houseID)
|
self._houseID = str(houseID)
|
||||||
|
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
|
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
|
|
||||||
# Get token
|
# Get token
|
||||||
@@ -208,14 +201,26 @@ class Source:
|
|||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for pickup in schedule:
|
for pickup in schedule:
|
||||||
|
# Get the waste type
|
||||||
waste_type = pickup.find_all(
|
waste_type = pickup.find_all(
|
||||||
"div", {"class": "fragment_presenter_template_show"}
|
"div", {"class": "fragment_presenter_template_show"}
|
||||||
)[0].text.strip()
|
)[0].text.strip()
|
||||||
waste_date = (
|
|
||||||
pickup.find("div", {"class": "bin-collection-next"})
|
try: # Get the next collection date
|
||||||
.attrs["data-current_value"]
|
waste_date = (
|
||||||
.strip()
|
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(
|
entries.append(
|
||||||
Collection(
|
Collection(
|
||||||
date=datetime.strptime(waste_date, "%d/%m/%Y %H:%M").date(),
|
date=datetime.strptime(waste_date, "%d/%m/%Y %H:%M").date(),
|
||||||
|
|||||||
@@ -34,5 +34,3 @@ waste_collection_schedule:
|
|||||||
postcode: "CR0 2EG"
|
postcode: "CR0 2EG"
|
||||||
houseID: "23B Howard Road"
|
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.
|
|
||||||
Reference in New Issue
Block a user