Repository: mampfes/hacs_waste_collection_schedule

Issue:
[Source Request]: Add  Hounslow Council  UK
### Municipality / Region

United Kingdom

### Collection Calendar Webpage

https://www.hounslow.gov.uk/homepage/86/recycling_and_waste_collection_day_finder

### Example Address

17 A Lapton road, TW3 4HS

### Collection Data Format

As html on a webpage

### Additional Information

_No response_


Discussion:
Implementation approach:

```python
r = requests.post("https://www.hounslow.gov.uk/homepage/86/recycling_and_waste_collection_day_finder", data={"UPRN": uprn})
soup = BeautifulSoup(r.text, features="html.parser")
... HTML Parsing ...
```



I am trying to build it but getting some error in config.  Can you please build it.?
   #   
       soup = BeautifulSoup(r.text, features="html.parser")
        # Find all div elements with class 'bincal_heading_wrapper'
        bin_cal_divs = soup.find_all('div', class_='bin_day_main_wrapper')

        print (bin_cal_divs)

        for bin_cal_div in bin_cal_divs:
            # Extract the address information
            address_h2 = bin_cal_div.find('h2')
            if address_h2:
                address = address_h2.text.strip()
                print(f"Address: {address}")
            collection_info = bin_cal_div.find_all('h4')
            for info in collection_info:
                date = info.text.strip()
                bins = [li.text.strip() for li in info.find_next('ul', class_='list-group').find_all('li')]
                print(f"Collection Date: {date}")
                print("Bins:")
                for bin in bins:
                    print(f"  - {bin}")
                    entries.append(
                        Collection(
                            date=date,
                            t=bin,
                            icon=ICON_MAP.get(bin),
                        )
                    )

            print("\n")
        return entries
         



Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/hounslow_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/hounslow_gov_uk.py
new file mode 100644
--- /dev/null
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/hounslow_gov_uk.py
@@ -0,0 +1,65 @@
+from datetime import datetime
+
+import requests
+from bs4 import BeautifulSoup
+from waste_collection_schedule import Collection  # type: ignore[attr-defined]
+
+TITLE = "London Borough of Hounslow"
+DESCRIPTION = "Source for London Borough of Hounslow."
+URL = "https://hounslow.gov.uk"
+TEST_CASES = {
+    "10090801236": {"uprn": 10090801236},
+    "100021552942": {"uprn": 100021552942},
+}
+
+
+ICON_MAP = {
+    "Black": "mdi:trash-can",
+    "Garden": "mdi:leaf",
+    "Recycling": "mdi:recycle",
+    "Food": "mdi:food",
+}
+
+
+API_URL = "https://www.hounslow.gov.uk/homepage/86/recycling_and_waste_collection_day_finder#collectionday"
+
+
+class Source:
+    def __init__(self, uprn: str | int):
+        self._uprn: str = str(uprn)
+
+    def fetch(self):
+        args = {
+            "UPRN": self._uprn,
+        }
+        r = requests.post(API_URL, data=args)
+        r.raise_for_status()
+        soup = BeautifulSoup(r.text, "html.parser")
+        bin_cal_divs = soup.find_all("div", class_="bin_day_main_wrapper")
+        entries = []
+
+        for bin_cal_div in bin_cal_divs:
+            # Extract the address information
+            collection_info = bin_cal_div.find_all("h4")
+            for info in collection_info:
+                date_splitted = info.text.strip().split("-")
+                date_str = (
+                    date_splitted[1] if len(date_splitted) > 1 else date_splitted[0]
+                ).strip()
+                try:
+                    date = datetime.strptime(date_str, "%d %b %Y").date()
+                except ValueError:
+                    date = datetime.strptime(date_str, "%A %d %b %Y").date()
+                bins = [
+                    li.text.strip()
+                    for li in info.find_next("ul", class_="list-group").find_all("li")
+                ]
+                for bin in bins:
+                    entries.append(
+                        Collection(
+                            date=date,
+                            t=bin,
+                            icon=ICON_MAP.get(bin.split(" ")[0]),
+                        )
+                    )
+        return entries


Test patch: