Skip to content

Commit 9db75a1

Browse files
committed
fix: #1606 - Brighton and Hove City Council
fix: #1606 - Brighton and Hove City Council
1 parent fa0ec28 commit 9db75a1

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

uk_bin_collection/uk_bin_collection/councils/BrightonandHoveCityCouncil.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def parse_data(self, page: str, **kwargs) -> dict:
7272
break
7373

7474
if not found:
75-
raise Exception(f"Address containing '{user_paon}' not found in dropdown options")
75+
raise Exception(
76+
f"Address containing '{user_paon}' not found in dropdown options"
77+
)
7678

7779
submit_btn = wait.until(
7880
EC.presence_of_element_located(
@@ -84,7 +86,7 @@ def parse_data(self, page: str, **kwargs) -> dict:
8486

8587
results = wait.until(
8688
EC.presence_of_element_located(
87-
(By.XPATH, f'//span[contains(@class,"collection-sub")]')
89+
(By.XPATH, f'//div[contains(@class,"mx-name-listView1")]')
8890
)
8991
)
9092

@@ -96,44 +98,21 @@ def parse_data(self, page: str, **kwargs) -> dict:
9698
current_date = datetime.now()
9799

98100
# Find all elements with class starting with 'mx-name-index-'
99-
bins = soup.find_all(class_=lambda x: x and x.startswith("mx-name-index-"))
101+
bin_view = soup.find(class_="mx-name-listView1")
102+
bins = bin_view.find_all(
103+
class_=lambda x: x and x.startswith("mx-name-index-")
104+
)
100105

101106
for bin_item in bins:
102-
bin_type = bin_item.find(class_="collection-main").text.strip()
103-
day_of_week_elements = bin_item.find_all(class_="collection-header")
104-
bin_date = None
105-
106-
for elem in day_of_week_elements:
107-
if (
108-
elem.text.strip() != bin_type
109-
): # Avoid taking the bin type as the date
110-
next_sibling = elem.find_next_sibling()
111-
if next_sibling:
112-
bin_date_str = next_sibling.text.strip()
113-
try:
114-
# Try parsing the date string in the format 'dd Month' (e.g., '30 Dec', '5 January')
115-
bin_date = datetime.strptime(bin_date_str, "%d %b")
116-
except ValueError:
117-
try:
118-
# If the above format fails, try 'dd MonthName' (e.g., '30 December', '5 January')
119-
bin_date = datetime.strptime(bin_date_str, "%d %B")
120-
except ValueError:
121-
pass
122-
123-
if bin_date:
124-
# Set the year based on the logic provided
125-
if bin_date.month < current_date.month:
126-
bin_date = bin_date.replace(
127-
year=current_date.year + 1
128-
)
129-
else:
130-
bin_date = bin_date.replace(year=current_date.year)
131-
# Format the date to the desired format
132-
bin_date = bin_date.strftime("%d/%m/%Y")
133-
break
107+
bin_type = bin_item.find(class_="mx-name-text31").text.strip()
108+
109+
bin_date_str = bin_item.find(class_="mx-name-text29").text.strip()
110+
111+
bin_date = datetime.strptime(bin_date_str, "%d %B %Y")
112+
bin_date = bin_date.strftime(date_format)
113+
134114
dict_data = {"type": bin_type, "collectionDate": bin_date}
135115
data["bins"].append(dict_data)
136-
print(data)
137116
except Exception as e:
138117
# Here you can log the exception if needed
139118
print(f"An error occurred: {e}")

0 commit comments

Comments
 (0)