-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
uk_bin_collection/tests/council_schemas/ConwyCountyBorough.schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
uk_bin_collection/uk_bin_collection/councils/ConwyCountyBorough.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |