Skip to content

Commit

Permalink
feat: Add support for Conwy council
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad committed Oct 30, 2023
1 parent 9d79942 commit f580f3f
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
48 changes: 48 additions & 0 deletions uk_bin_collection/tests/council_schemas/ConwyCountyBorough.schema
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Feature: Test each council output matches expected results in /outputs
| CharnwoodBoroughCouncil |
| ChelmsfordCityCouncil |
| CheshireEastCouncil |
| ConwyCountyBorough |
| CrawleyBoroughCouncil |
| CroydonCouncil |
| DerbyshireDalesDistrictCouncil |
Expand Down
7 changes: 7 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions uk_bin_collection/tests/outputs/ConwyCountyBorough.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
40 changes: 40 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/ConwyCountyBorough.py
Original file line number Diff line number Diff line change
@@ -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'<li>([^<]+)<'

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

0 comments on commit f580f3f

Please sign in to comment.