Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for Conwy council #400

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading