diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index e6ee62dee2..dec5138af7 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -69,11 +69,11 @@ "wiki_note": "In order to use this parser, you must provide a valid postcode and a uprn retrieved from the councils website for your specific address" }, "BelfastCityCouncil": { + "postcode": "BT10 0GY", "skip_get_url": true, + "uprn": "185086469", "url": "https://online.belfastcity.gov.uk/find-bin-collection-day/Default.aspx", - "wiki_name": "BelfastCityCouncil", - "postcode": "BT10 0GY", - "uprn": "185086469" + "wiki_name": "BelfastCityCouncil" }, "BexleyCouncil": { "house_number": "1 Dorchester Avenue, Bexley", @@ -298,8 +298,8 @@ }, "DorsetCouncil": { "skip_get_url": true, - "url": "https://www.dorsetcouncil.gov.uk/", "uprn": "100040711049", + "url": "https://www.dorsetcouncil.gov.uk/", "wiki_name": "Dorset Council" }, "DoverDistrictCouncil": { @@ -360,12 +360,12 @@ "wiki_name": "Eastleigh Borough Council" }, "EnfieldCouncil": { - "url": "https://www.enfield.gov.uk/services/rubbish-and-recycling/find-my-collection-day", - "wiki_name": "Enfield Council", - "skip_get_url": true, - "postcode": "N13 5AJ", "house_number": "111", - "web_driver": "http://selenium:4444" + "postcode": "N13 5AJ", + "skip_get_url": true, + "url": "https://www.enfield.gov.uk/services/rubbish-and-recycling/find-my-collection-day", + "web_driver": "http://selenium:4444", + "wiki_name": "Enfield Council" }, "EnvironmentFirst": { "url": "https://environmentfirst.co.uk/house.php?uprn=100060055444", @@ -599,9 +599,9 @@ "postcode": "RH16 1SS", "skip_get_url": true, "url": "https://www.midsussex.gov.uk/waste-recycling/bin-collection/", + "web_driver": "http://selenium:4444", "wiki_name": "Mid Sussex District Council", - "wiki_note": "Pass the name of the street with the house number parameter, wrapped in double quotes", - "web_driver": "http://selenium:4444" + "wiki_note": "Pass the name of the street with the house number parameter, wrapped in double quotes" }, "MiltonKeynesCityCouncil": { "uprn": "Fullers Slade", @@ -813,6 +813,11 @@ "wiki_name": "Rochford Council", "wiki_note": "No extra parameters are required. Dates presented should be read as 'week commencing'." }, + "RotherhamCouncil": { + "url": "https://www.rotherham.gov.uk/bin-collections\\?address\\=100050866000\\&submit\\=Submit", + "uprn": "100050866000", + "wiki_name": "RotherhamCouncil" + }, "RugbyBoroughCouncil": { "postcode": "CV22 6LA", "skip_get_url": true, @@ -1199,12 +1204,12 @@ "wiki_note": "Works with all collection areas that use Joint Waste Solutions. Just use the correct URL." }, "WychavonDistrictCouncil": { + "postcode": "WR3 7RU", + "skip_get_url": true, + "uprn": "100120716273", "url": "https://selfservice.wychavon.gov.uk/wdcroundlookup/wdc_search.jsp", - "wiki_name": "WychavonDistrictCouncil", "web_driver": "http://selenium:4444", - "skip_get_url": true, - "postcode": "WR3 7RU", - "uprn": "100120716273" + "wiki_name": "WychavonDistrictCouncil" }, "WyreCouncil": { "postcode": "FY6 8HG", diff --git a/uk_bin_collection/uk_bin_collection/councils/RotherhamCouncil.py b/uk_bin_collection/uk_bin_collection/councils/RotherhamCouncil.py new file mode 100644 index 0000000000..63c7e7ac1b --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/RotherhamCouncil.py @@ -0,0 +1,51 @@ +from bs4 import BeautifulSoup +from uk_bin_collection.uk_bin_collection.common import * +from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass + + +# import the wonderful Beautiful Soup and the URL grabber +class CouncilClass(AbstractGetBinDataClass): + """ + Concrete classes have to implement all abstract operations of the + base class. They can also override some operations with a default + implementation. + """ + + def parse_data(self, page: str, **kwargs) -> dict: + user_uprn = kwargs.get("uprn") + + check_uprn(user_uprn) + + response = requests.post( + "https://www.rotherham.gov.uk/bin-collections?address={}&submit=Submit".format(user_uprn) + ) + # Make a BS4 object + soup = BeautifulSoup(response.text, features="html.parser") + soup.prettify() + + data = {"bins": []} + + table = soup.select('table')[0] + + if table: + rows = table.select('tr') + + for index, row in enumerate(rows): + bin_info_cell = row.select('td') + if bin_info_cell: + bin_type = bin_info_cell[0].get_text(separator=' ', strip=True) + bin_collection = bin_info_cell[1] + + if bin_collection: + dict_data = { + "type": bin_type.title(), + "collectionDate": datetime.strptime( + bin_collection.get_text(strip=True), "%A, %d %B %Y" + ).strftime(date_format), + } + + data["bins"].append(dict_data) + else: + print("Something went wrong. Please open a GitHub issue.") + + return data