diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 5add0d3a4d..293288e509 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -283,10 +283,10 @@ "wiki_name": "Doncaster Council" }, "DorsetCouncil": { - "url": "https://gi.dorsetcouncil.gov.uk/mapping/mylocal/viewresults/100040711049", - "wiki_command_url_override": "https://gi.dorsetcouncil.gov.uk/mapping/mylocal/viewresults/XXXXXXXX", - "wiki_name": "Dorset Council", - "wiki_note": "Replace XXXXXXXX with UPRN." + "skip_get_url": true, + "url": "https://www.dorsetcouncil.gov.uk/", + "uprn": "100040711049", + "wiki_name": "Dorset Council" }, "DoverDistrictCouncil": { "url": "https://collections.dover.gov.uk/property/100060908340", diff --git a/uk_bin_collection/uk_bin_collection/councils/DorsetCouncil.py b/uk_bin_collection/uk_bin_collection/councils/DorsetCouncil.py index c39286c53b..c9adfefd2c 100644 --- a/uk_bin_collection/uk_bin_collection/councils/DorsetCouncil.py +++ b/uk_bin_collection/uk_bin_collection/councils/DorsetCouncil.py @@ -14,38 +14,22 @@ class CouncilClass(AbstractGetBinDataClass): def parse_data(self, page: str, **kwargs) -> dict: data = {"bins": []} collections = [] - - # Parse the page and find all the result boxes - soup = BeautifulSoup(page.text, features="html.parser") - soup.prettify() - results = soup.find_all("li", {"class": "resultListItem"}) - - # If the result box has a wanted string in, we can use it. Check the contents of each box and find the - # desired text and dates - for r in results: - if "Your next" in r.text: - if type(r.contents[10]) is element.NavigableString: - bin_text = r.contents[10].text.split(" ")[2].title() + " bin" - bin_date = datetime.strptime( - remove_ordinal_indicator_from_date_string( - r.contents[11].text.strip() - ), - "%A %d %B %Y", - ) - else: - bin_text = r.contents[11].text.split(" ")[2].title() + " bin" - bin_date = datetime.strptime( - remove_ordinal_indicator_from_date_string( - r.contents[12].text.strip() - ), - "%A %d %B %Y", - ) - - if bin_date.date() >= datetime.now().date(): - collections.append((bin_text, bin_date)) - - # Sort the text and date elements by date - ordered_data = sorted(collections, key=lambda x: x[1]) + url_base = "https://geoapi.dorsetcouncil.gov.uk/v1/services/" + url_types = ["recyclingday", "refuseday", "foodwasteday", "gardenwasteday"] + + uprn = kwargs.get("uprn") + # Check the UPRN is valid + check_uprn(uprn) + + for url_type in url_types: + response = requests.get(f"{url_base}{url_type}/{uprn}") + if response.status_code != 200: + raise ConnectionError(f"Could not fetch from {url_type} endpoint") + json_data = response.json()["values"][0] + collections.append((f"{json_data.get('type')} bin", datetime.strptime(json_data.get('dateNextVisit'), "%Y-%m-%d"))) + + # Sort the text and date elements by date + ordered_data = sorted(collections, key=lambda x: x[1]) # Put the elements into the dictionary for item in ordered_data: diff --git a/uk_bin_collection/uk_bin_collection/get_bin_data.py b/uk_bin_collection/uk_bin_collection/get_bin_data.py index bc15ab32d5..0ee809358d 100644 --- a/uk_bin_collection/uk_bin_collection/get_bin_data.py +++ b/uk_bin_collection/uk_bin_collection/get_bin_data.py @@ -5,7 +5,7 @@ """ import json -import logging +import logging, logging.config from abc import ABC, abstractmethod import os import requests