Repository: mampfes/hacs_waste_collection_schedule

Issue:
Changes to Campbelltown Council URLs and APIs have broken the ability to retrieve waste collection info (campbelltown_nsw_gov_au.py)
Hi there,

I'm absolutely useless with Python or I'd be coding a fix and lodging a pull request, but instead am posting this as an issue at the community's mercy :)

The Campbelltown Council (Australia) API URLs have changed, and I believe that they're now presenting address search data a little differently too - XML instead of JSON.

The overall pattern still appears to be the same:

1. Retrieve the GeolocationID for a given address via the 'address_search' API
2. Plug that GeolocationID into the 'collection' API to retrieve the waste collection info in HTML format, wrapped in JSON

**URLs in existing version of Campbelltown NSW AU Waste Collection Source:**
```
API_URLS = {
    "address_search": "https://www.campbelltown.nsw.gov.au/ocsvc/public/spatial/findaddress?address={}",
    "collection": "https://www.campbelltown.nsw.gov.au/ocsvc/Public/InMyNeighbourhood/WasteServices?GeoLocationId={}",
}
```

**URLs that work now:**
```
API_URLS = {
    "address_search": "https://www.campbelltown.nsw.gov.au/api/v1/myarea/search?keywords={}",
    "collection": "https://www.campbelltown.nsw.gov.au/ocapi/Public/myarea/wasteservices?geolocationid={}&ocsvclang=en-AU",
}
```

I'm not familiar with the old Campbelltown address search API, but looking at the code it appears that it used to return JSON data. It's now returning pure XML. 

**Examples using the new API URLs:**
Address search result: [https://www.campbelltown.nsw.gov.au/api/v1/myarea/search?keywords=10%20Brookfield%20Road%20Minto%20NSW%202566](https://www.campbelltown.nsw.gov.au/api/v1/myarea/search?keywords=10%20Brookfield%20Road%20Minto%20NSW%202566)

Collection API result for the above GeolocationID: [https://www.campbelltown.nsw.gov.au/ocapi/Public/myarea/wasteservices?geolocationid=401ee13b-b04c-4948-82e4-09d274c479a0&ocsvclang=en-AU](https://www.campbelltown.nsw.gov.au/ocapi/Public/myarea/wasteservices?geolocationid=401ee13b-b04c-4948-82e4-09d274c479a0&ocsvclang=en-AU)


Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/campbelltown_nsw_gov_au.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/campbelltown_nsw_gov_au.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/campbelltown_nsw_gov_au.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/campbelltown_nsw_gov_au.py
@@ -31,8 +31,8 @@
 }
 
 API_URLS = {
-    "address_search": "https://www.campbelltown.nsw.gov.au/ocsvc/public/spatial/findaddress?address={}",
-    "collection": "https://www.campbelltown.nsw.gov.au/ocsvc/Public/InMyNeighbourhood/WasteServices?GeoLocationId={}",
+    "address_search": "https://www.campbelltown.nsw.gov.au/api/v1/myarea/search?keywords={}",
+    "collection": "https://www.campbelltown.nsw.gov.au/ocapi/Public/myarea/wasteservices?geolocationid={}&ocsvclang=en-AU",
 }
 
 HEADERS = {"user-agent": "Mozilla/5.0"}
@@ -43,7 +43,6 @@
     "Green Waste": "mdi:leaf",
 }
 
-
 class Source:
     def __init__(
         self, post_code: str, suburb: str, street_name: str, street_number: str
@@ -68,7 +67,7 @@ def fetch(self):
         data = json.loads(r.text)
 
         # Find the ID for our suburb
-        for item in data["locations"]:
+        for item in data["Items"]:
             locationId = item["Id"]
             break
 
@@ -85,20 +84,28 @@ def fetch(self):
         responseContent = data["responseContent"]
 
         soup = BeautifulSoup(responseContent, "html.parser")
-        services = soup.find_all("div", attrs={"class": "service-details"})
+        services = soup.find_all("div", attrs={"class": "waste-services-result"})
 
         entries = []
 
         for item in services:
             # test if <div> contains a valid date. If not, is is not a collection item.
-            date_text = item.find("span")
+            date_text = item.find("div", attrs={"class": "next-service"})
+            
+            # The date format currently used on https://www.campbelltown.nsw.gov.au/Services-and-Facilities/Waste-and-Recycling/Check-my-collection-day
+            date_format = '%a %d/%m/%Y'
+
             try:
-                date = datetime.datetime.strptime(date_text.text, "%A%d %b %Y").date()
+                # Strip carriage returns and newlines out of the HTML content
+                cleaned_date_text = date_text.text.replace('\r','').replace('\n','').strip()
+
+                # Parse the date
+                date = datetime.datetime.strptime(cleaned_date_text, date_format).date()
 
             except ValueError:
                 continue
 
-            waste_type = item.contents[0].strip()
+            waste_type = item.find("h3").text.strip()
 
             entries.append(
                 Collection(


Test patch: