Skip to content

Commit 2b71827

Browse files
committed
fix: #1520 - Erewash Borough Council
fix: #1520 - Erewash Borough Council
1 parent 5c0fb1d commit 2b71827

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

uk_bin_collection/tests/input.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@
885885
"ErewashBoroughCouncil": {
886886
"skip_get_url": true,
887887
"uprn": "10003582028",
888-
"url": "https://map.erewash.gov.uk/isharelive.web/myerewash.aspx",
888+
"url": "https://www.erewash.gov.uk",
889889
"wiki_name": "Erewash",
890890
"wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search).",
891891
"LAD24CD": "E07000036"
Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import json
2+
13
from bs4 import BeautifulSoup
4+
25
from uk_bin_collection.uk_bin_collection.common import *
36
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
47

@@ -16,46 +19,41 @@ def parse_data(self, page: str, **kwargs) -> dict:
1619
uprn = kwargs.get("uprn")
1720
check_uprn(uprn)
1821

22+
label_map = {
23+
"domestic-waste-collection-service": "Household Waste",
24+
"recycling-collection-service": "Recycling",
25+
"garden-waste-collection-service": "Garden Waste",
26+
}
27+
1928
requests.packages.urllib3.disable_warnings()
2029
response = requests.get(
21-
f"https://map.erewash.gov.uk/isharelive.web/myerewash.aspx?action=SetAddress&UniqueId={uprn}",
30+
f"https://www.erewash.gov.uk/bbd-whitespace/one-year-collection-dates-without-christmas?uprn={uprn}",
2231
headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)"},
2332
)
33+
# Parse the JSON response
34+
payload = response.json()
35+
bin_collection = json.loads(payload) if isinstance(payload, str) else payload
2436

25-
soup = BeautifulSoup(response.text, features="html.parser")
26-
collections = soup.find("div", {"aria-label": "Waste Collection"}).find_all(
27-
"div", {"class": "atPanelContent"}
37+
cd = next(
38+
i["settings"]["collection_dates"]
39+
for i in bin_collection
40+
if i.get("command") == "settings"
2841
)
29-
for c in collections:
30-
bin_type = c.find("h4").get_text(strip=True)
31-
if "my next" in bin_type.lower():
32-
collection_info = c.find("div", {"class": "atPanelData"}).get_text(
33-
strip=True
34-
)
35-
results = re.search(
36-
"([A-Za-z]+ \\d+[A-Za-z]+ [A-Za-z]+ \\d*)", collection_info
42+
43+
for month in cd.values():
44+
for e in month:
45+
d = e["date"] # "YYYY-MM-DD"
46+
label = label_map.get(
47+
e.get("service-identifier"),
48+
e.get("service") or e.get("service-identifier"),
3749
)
38-
if results:
39-
collection_date = datetime.strptime(
40-
remove_ordinal_indicator_from_date_string(results[1]).strip(),
41-
"%A %d %B %Y",
42-
).strftime(date_format)
43-
dict_data = {
44-
"type": bin_type.replace("My Next ", "").replace(
45-
" Collection", ""
46-
),
47-
"collectionDate": collection_date,
48-
}
49-
data["bins"].append(dict_data)
50-
if "garden waste" in collection_info.lower():
51-
dict_data = {
52-
"type": "Garden Waste",
53-
"collectionDate": collection_date,
54-
}
55-
data["bins"].append(dict_data)
56-
57-
data["bins"].sort(
58-
key=lambda x: datetime.strptime(x.get("collectionDate"), date_format)
59-
)
50+
51+
dict_data = {
52+
"type": label,
53+
"collectionDate": datetime.strptime(d, "%Y-%m-%d").strftime(
54+
date_format
55+
),
56+
}
57+
data["bins"].append(dict_data)
6058

6159
return data

0 commit comments

Comments
 (0)