Skip to content

Commit 5b67cf5

Browse files
feat: handle changes to northumberland council website
1 parent 6f1ccc6 commit 5b67cf5

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

uk_bin_collection/tests/input.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,8 +1779,8 @@
17791779
"LAD24CD": "E06000065"
17801780
},
17811781
"NorthumberlandCouncil": {
1782-
"uprn": "10093091235",
1783-
"postcode": "NE46 1UQ",
1782+
"uprn": "010096302588",
1783+
"postcode": "NE65 0ZP",
17841784
"skip_get_url": true,
17851785
"url": "https://bincollection.northumberland.gov.uk/postcode",
17861786
"web_driver": "http://selenium:4444",

uk_bin_collection/uk_bin_collection/councils/NorthumberlandCouncil.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ def parse_data(self, page: str, **kwargs) -> dict:
5252

5353
# Wait for and click cookie button
5454
cookie_button = wait.until(
55-
EC.element_to_be_clickable(By.CLASS_NAME, "accept-all")
55+
EC.element_to_be_clickable(
56+
(By.CLASS_NAME, "accept-all")
57+
)
5658
)
5759
cookie_button.click()
5860

5961
# Wait for and find postcode input
6062
inputElement_pc = wait.until(
61-
EC.presence_of_element_located((By.ID, "postcode")
63+
EC.presence_of_element_located(
64+
(By.ID, "postcode")
65+
)
6266
)
6367

6468
# Enter postcode and submit
@@ -67,7 +71,9 @@ def parse_data(self, page: str, **kwargs) -> dict:
6771

6872
# Wait for and find house number input
6973
selectElement_address = wait.until(
70-
EC.presence_of_element_located(By.ID, "address")
74+
EC.presence_of_element_located(
75+
(By.ID, "address")
76+
)
7177
)
7278

7379
dropdown = Select(selectElement_address)
@@ -99,16 +105,16 @@ def parse_data(self, page: str, **kwargs) -> dict:
99105
# - cell 1 is the date in format eg. 9 September (so no year value 🥲)
100106
# - cell 2 is the day name, not useful
101107
# - cell 3 is the bin type eg. "General waste", "Recycling", "Garden waste"
102-
rows = soup.find_all("tr", class_="govuk-table__row")
108+
rows = soup.find("tbody", class_="govuk-table__body").find_all("tr", class_="govuk-table__row")
103109

104110
for row in rows:
105111
bin_type=row.find_all("td")[-1].text.strip()
106112

107113
collection_date_string = row.find('th').text.strip()
108114

109115
# sometimes but not always the day is written "22nd" instead of 22 so make sure we get a proper int
110-
collection_date_day = [int(i) for i in collection_date_string.split(' ').split() if i.isdigit()]
111-
collection_date_month_name = collection_date_string.split(' ')[1]
116+
collection_date_day = "".join([i for i in list(collection_date_string.split(" ")[0]) if i.isdigit()])
117+
collection_date_month_name = collection_date_string.split(" ")[1]
112118

113119
# if we are currently in Oct, Nov, or Dec and the collection month is Jan, Feb, or Mar, let's assume its next year
114120
if (current_month >= 10) and (collection_date_month_name in ["January", "February", "March"]):
@@ -117,7 +123,7 @@ def parse_data(self, page: str, **kwargs) -> dict:
117123
collection_date_year = current_year
118124

119125
collection_date = time.strptime(
120-
f"{collection_date_day[0]} {collection_date_month_name} {collection_date_year}", "%d %B %Y"
126+
f"{collection_date_day} {collection_date_month_name} {collection_date_year}", "%d %B %Y"
121127
)
122128

123129
# Add it to the data

0 commit comments

Comments
 (0)