mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
Add Braintree, UK
This commit is contained in:
@@ -185,6 +185,7 @@ Currently the following service providers are supported:
|
|||||||
|
|
||||||
- [Bracknell Forest Council - bracknell-forest.gov.uk](./doc/source/bracknell_forest_gov_uk.md)
|
- [Bracknell Forest Council - bracknell-forest.gov.uk](./doc/source/bracknell_forest_gov_uk.md)
|
||||||
- [Bradford Metropolitan District Council - bradford.gov.uk](./doc/source/bradford_gov_uk.md)
|
- [Bradford Metropolitan District Council - bradford.gov.uk](./doc/source/bradford_gov_uk.md)
|
||||||
|
- [Braintree District Council - bracknell-forest.gov.uk](./doc/source/braintree_gov_uk.md)
|
||||||
- [Cambridge City Council - cambridge.gov.uk](./doc/source/cambridge_gov_uk.md)
|
- [Cambridge City Council - cambridge.gov.uk](./doc/source/cambridge_gov_uk.md)
|
||||||
- [Canterbury City Council - canterbury.gov.uk](./doc/source/canterbury_gov_uk.md)
|
- [Canterbury City Council - canterbury.gov.uk](./doc/source/canterbury_gov_uk.md)
|
||||||
- [Cheshire East Council - cheshireeast.gov.uk](./doc/source/cheshire_east_gov_uk.md)
|
- [Cheshire East Council - cheshireeast.gov.uk](./doc/source/cheshire_east_gov_uk.md)
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from dateutil import parser
|
||||||
|
from waste_collection_schedule import Collection
|
||||||
|
|
||||||
|
TITLE = "braintree.gov.uk"
|
||||||
|
DESCRIPTION = "Braintree District Council, UK - Waste Collection"
|
||||||
|
URL = "https://www.braintree.gov.uk"
|
||||||
|
TEST_CASES = {
|
||||||
|
"30 Boars Tye Road": {"house_number": "30", "post_code": "CM8 3QE"},
|
||||||
|
"64 Silver Street": {"house_number": "64", "post_code": "CM8 3QG"},
|
||||||
|
"18 St Mary's Road": {"house_number": "1", "post_code": "CM8 3PE"},
|
||||||
|
"20 Peel Crescent": {"house_number": "20", "post_code": "CM7 2RS"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ICONS = {
|
||||||
|
"Grey Bin": "mdi:trash-can",
|
||||||
|
"Clear Sack": "mdi:recycle",
|
||||||
|
"Green Bin": "mdi:leaf",
|
||||||
|
"Food Bin": "mdi:food-apple",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Source:
|
||||||
|
def __init__(self, post_code: str, house_number: str):
|
||||||
|
self.post_code = post_code
|
||||||
|
self.house_number = house_number
|
||||||
|
self.url = f"{URL}/xfp/form/554"
|
||||||
|
self.form_data = {
|
||||||
|
"qe15dda0155d237d1ea161004d1839e3369ed4831_0_0": (None, post_code),
|
||||||
|
"page": (None, 5730),
|
||||||
|
}
|
||||||
|
|
||||||
|
def fetch(self):
|
||||||
|
address_lookup = requests.post("https://www.braintree.gov.uk/xfp/form/554", files=self.form_data)
|
||||||
|
address_lookup.raise_for_status()
|
||||||
|
addresses = {}
|
||||||
|
for address in BeautifulSoup(address_lookup.text, "html.parser").find_all('option'):
|
||||||
|
if len(address['value']) == 12:
|
||||||
|
addresses[address['value']] = address.text.strip()
|
||||||
|
id = next(address for address in addresses if addresses[address].startswith(self.house_number))
|
||||||
|
self.form_data["qe15dda0155d237d1ea161004d1839e3369ed4831_1_0"] = (None, id)
|
||||||
|
self.form_data["next"] = (None, "Next")
|
||||||
|
collection_lookup = requests.post("https://www.braintree.gov.uk/xfp/form/554", files=self.form_data)
|
||||||
|
collection_lookup.raise_for_status()
|
||||||
|
entries = []
|
||||||
|
for results in BeautifulSoup(collection_lookup.text, "html.parser").find_all('div', class_="date_display"):
|
||||||
|
try:
|
||||||
|
collection_type, collection_date = results.text.strip().split("\n")
|
||||||
|
entries.append(
|
||||||
|
Collection(
|
||||||
|
date=parser.parse(collection_date).date(),
|
||||||
|
t=collection_type,
|
||||||
|
icon=ICONS[collection_type]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except (StopIteration, TypeError):
|
||||||
|
pass
|
||||||
|
return entries
|
||||||
33
doc/source/braintree_gov_uk.md
Normal file
33
doc/source/braintree_gov_uk.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Bracknell Forest Council
|
||||||
|
|
||||||
|
Support for schedules provided by [Braintree District Council](https://www.braintree.gov.uk/xfp/form/554), serving Braintree, UK.
|
||||||
|
|
||||||
|
## Configuration via configuration.yaml
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
waste_collection_schedule:
|
||||||
|
sources:
|
||||||
|
- name: braintree_gov_uk
|
||||||
|
args:
|
||||||
|
post_code: Post Code
|
||||||
|
house_number: House Number
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration Variables
|
||||||
|
|
||||||
|
**post_code**<br>
|
||||||
|
*(string) (required)*
|
||||||
|
|
||||||
|
**house_number**<br>
|
||||||
|
*(string) (required)*
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
waste_collection_schedule:
|
||||||
|
sources:
|
||||||
|
- name: braintree_gov_uk
|
||||||
|
args:
|
||||||
|
post_code: "CM8 3QE"
|
||||||
|
house_number: "30"
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user