Skip to content

Commit fc05b2d

Browse files
committed
fix: Wiltshire Council
fix: #1533
1 parent 9b27224 commit fc05b2d

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

uk_bin_collection/uk_bin_collection/councils/WiltshireCouncil.py

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from bs4 import BeautifulSoup
24

35
from uk_bin_collection.uk_bin_collection.common import *
@@ -91,40 +93,56 @@ def parse_data(self, page: str, **kwargs) -> dict:
9193

9294
soup = BeautifulSoup(response.text, features="html.parser")
9395
soup.prettify()
94-
96+
# print(soup)
9597
# Find all the bits of the current calendar that contain an event
96-
events = soup.find_all("div", {"class": "rc-event-container"})
98+
resultscontainer = soup.find_all("div", {"class": "results-container"})
9799

98-
for event in events:
99-
# Get the date and type of each bin collection
100-
bin_date = datetime.strptime(
101-
event.find_next("a").attrs.get("data-original-datetext"),
102-
"%A %d %B, %Y",
100+
for result in resultscontainer:
101+
rows = result.find_all(
102+
"div", {"class": "col-12 col-sm-6 col-md-4 col-lg-4 mb-4"}
103103
)
104-
bin_type = event.find_next("a").attrs.get("data-original-title")
105-
# Only process it if it's today or in the future
106-
if bin_date.date() >= datetime.now().date():
107-
# Split the really long type up into two separate bins
108-
if (
109-
bin_type
110-
== "Mixed dry recycling (blue lidded bin) and glass (black box or basket)"
111-
):
112-
collections.append(
113-
(
114-
"Mixed dry recycling (blue lidded bin)",
115-
datetime.strftime(bin_date, date_format),
104+
for row in rows:
105+
cardcollectionday = row.find(
106+
"span", {"class": "card-collection-day"}
107+
)
108+
cardcollectiondate = row.find(
109+
"span", {"class": "card-collection-date"}
110+
)
111+
cardcollectionmonth = row.find(
112+
"span", {"class": "card-collection-month"}
113+
)
114+
bin_type = row.find(
115+
"li", {"class": re.compile(r"collection-type-...$")}
116+
).text
117+
118+
collection_date = f"{cardcollectionday.text}{cardcollectiondate.text}{cardcollectionmonth.text}"
119+
bin_date = datetime.strptime(
120+
collection_date,
121+
"%A %d %B %Y",
122+
)
123+
124+
if bin_date.date() >= datetime.now().date():
125+
# Split the really long type up into two separate bins
126+
if (
127+
bin_type
128+
== "Mixed dry recycling (blue lidded bin) and glass (black box or basket)"
129+
):
130+
collections.append(
131+
(
132+
"Mixed dry recycling (blue lidded bin)",
133+
datetime.strftime(bin_date, date_format),
134+
)
135+
)
136+
collections.append(
137+
(
138+
"Glass (black box or basket)",
139+
datetime.strftime(bin_date, date_format),
140+
)
116141
)
117-
)
118-
collections.append(
119-
(
120-
"Glass (black box or basket)",
121-
datetime.strftime(bin_date, date_format),
142+
else:
143+
collections.append(
144+
(bin_type, datetime.strftime(bin_date, date_format))
122145
)
123-
)
124-
else:
125-
collections.append(
126-
(bin_type, datetime.strftime(bin_date, date_format))
127-
)
128146

129147
data = {"bins": []}
130148

0 commit comments

Comments
 (0)