diff --git a/uk_bin_collection/tests/council_schemas/ConwyCountyBorough.schema b/uk_bin_collection/tests/council_schemas/ConwyCountyBorough.schema new file mode 100644 index 0000000000..04e0f1e479 --- /dev/null +++ b/uk_bin_collection/tests/council_schemas/ConwyCountyBorough.schema @@ -0,0 +1,48 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "$ref": "#/definitions/Welcome8", + "definitions": { + "Welcome8": { + "type": "object", + "additionalProperties": false, + "properties": { + "bins": { + "type": "array", + "items": { + "$ref": "#/definitions/Bin" + } + } + }, + "required": [ + "bins" + ], + "title": "Welcome8" + }, + "Bin": { + "type": "object", + "additionalProperties": false, + "properties": { + "type": { + "$ref": "#/definitions/Type" + }, + "collectionDate": { + "type": "string" + } + }, + "required": [ + "collectionDate", + "type" + ], + "title": "Bin" + }, + "Type": { + "type": "string", + "enum": [ + "Empty Standard Mixed Recycling", + "Empty Standard Garden Waste", + "Empty Standard General Waste" + ], + "title": "Type" + } + } +} \ No newline at end of file diff --git a/uk_bin_collection/tests/features/validate_council_outputs.feature b/uk_bin_collection/tests/features/validate_council_outputs.feature index 48a3d1c3c4..2d427cb871 100644 --- a/uk_bin_collection/tests/features/validate_council_outputs.feature +++ b/uk_bin_collection/tests/features/validate_council_outputs.feature @@ -27,6 +27,7 @@ Feature: Test each council output matches expected results in /outputs | CharnwoodBoroughCouncil | | ChelmsfordCityCouncil | | CheshireEastCouncil | + | ConwyCountyBorough | | CrawleyBoroughCouncil | | CroydonCouncil | | DerbyshireDalesDistrictCouncil | diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 0cee5e95c6..6fa8f1f9ba 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -125,6 +125,13 @@ "wiki_name": "Cheshire East Council", "wiki_note": "Both the UPRN and a one-line address are passed in the URL, which needs to be wrapped in double quotes. The one-line address is made up of the house number, street name and postcode.\nUse the form [here](https://online.cheshireeast.gov.uk/mycollectionday/) to find them, then take the first line and post code and replace all spaces with `%20`." }, + "ConwyCountyBorough": { + "postcode": "LL30 2DF", + "uprn": "100100429249", + "url": "https://www.conwy.gov.uk/Contensis-Forms/erf/collection-result-soap-xmas.asp?ilangid=1&uprn=100100429249", + "wiki_name": "Conwy County Borough Council", + "wiki_note": "Conwy County Borough Council is a straight up uprn in the url eg &uprn=XXXXXXXXXXXXX ." + }, "CrawleyBoroughCouncil": { "SKIP_GET_URL": "SKIP_GET_URL", "house_number": "9701076", diff --git a/uk_bin_collection/tests/outputs/ConwyCountyBorough.json b/uk_bin_collection/tests/outputs/ConwyCountyBorough.json new file mode 100644 index 0000000000..52024cbbf4 --- /dev/null +++ b/uk_bin_collection/tests/outputs/ConwyCountyBorough.json @@ -0,0 +1,40 @@ +{ + "bins": [ + { + "type": "Garden waste collection", + "collectionDate": "02/11/2023" + }, + { + "type": "Electrical and textile collection", + "collectionDate": "02/11/2023" + }, + { + "type": "Recycle & food waste collection", + "collectionDate": "02/11/2023" + }, + { + "type": "Recycle & food waste collection", + "collectionDate": "09/11/2023" + }, + { + "type": "Garden waste collection", + "collectionDate": "16/11/2023" + }, + { + "type": "Electrical and textile collection", + "collectionDate": "16/11/2023" + }, + { + "type": "Recycle & food waste collection", + "collectionDate": "16/11/2023" + }, + { + "type": "Refuse collection", + "collectionDate": "16/11/2023" + }, + { + "type": "Recycle & food waste collection", + "collectionDate": "23/11/2023" + } + ] +} \ No newline at end of file diff --git a/uk_bin_collection/uk_bin_collection/councils/ConwyCountyBorough.py b/uk_bin_collection/uk_bin_collection/councils/ConwyCountyBorough.py new file mode 100644 index 0000000000..2a9f452c7c --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/ConwyCountyBorough.py @@ -0,0 +1,40 @@ +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 re + +# 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: + # Make a BS4 object + soup = BeautifulSoup(page.text, features="html.parser") + soup.prettify() + + regex_pattern = r'
  • ([^<]+)<' + + data = {"bins": []} + + for bins in soup.select('div[class*="containererf"]'): + + collection_date = datetime.strptime(bins.find(id="content").text.strip(), "%A, %d/%m/%Y") + bin_type_div = bins.find(id='main1') + bin_types = bin_type_div.findAll('li') + for bin_type in bin_types: + + bin_type_name = re.sub(r'\(.*\)', '', bin_type.text).strip() + + dict_data = { + "type": bin_type_name, + "collectionDate": collection_date.strftime(date_format) + } + data["bins"].append(dict_data) + + return data