Adding bromsgrove gov uk (#2090)

* Added Bromsgrove UK

* Added missing comment

* Fixed bug retireving icon

* Updated info.md and README.md

* Corrected display name

* refromatting

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
Co-authored-by: 5ila5 <38183212+5ila5@users.noreply.github.com>
This commit is contained in:
MrMaxP
2024-05-22 20:34:24 +01:00
committed by GitHub
parent 3afa6f1ad0
commit 5f0adcec02
4 changed files with 151 additions and 1 deletions

View File

@@ -1223,6 +1223,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Breckland Council](/doc/source/breckland_gov_uk.md) / breckland.gov.uk/mybreckland
- [Bristol City Council](/doc/source/bristol_gov_uk.md) / bristol.gov.uk
- [Broadland District Council](/doc/source/south_norfolk_and_broadland_gov_uk.md) / area.southnorfolkandbroadland.gov.uk
- [Bromsgrove City Council](/doc/source/bromsgrove_gov_uk.md) / bromsgrove.gov.uk
- [Broxtowe Borough Council](/doc/source/broxtowe_gov_uk.md) / broxtowe.gov.uk
- [Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas](/doc/source/chiltern_gov_uk.md) / chiltern.gov.uk
- [Burnley Council](/doc/source/burnley_gov_uk.md) / burnley.gov.uk

View File

@@ -0,0 +1,94 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Bromsgrove City Council"
DESCRIPTION = "Source for bromsgrove.gov.uk services for Bromsgrove, UK."
URL = "https://bromsgrove.gov.uk"
TEST_CASES = {
"Shakespeare House": {"uprn": "10094552413", "postcode": "B61 8DA"},
"The Lodge": {"uprn": 10000218025, "postcode": "B60 2AA"},
"Ceader Lodge": {"uprn": 100120576392, "postcode": "B60 2JS"},
"Finstall Road": {"uprn": 100120571971, "postcode": "B60 3DE"},
}
HEADERS = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
}
API_URLS = {
"collection": "https://bincollections.bromsgrove.gov.uk/BinCollections/Details/",
}
ICON_MAP = {
"Grey": "mdi:trash-can",
"Green": "mdi:recycle",
"Brown": "mdi:leaf",
}
class Source:
def __init__(self, uprn: str, postcode: str):
self._uprn = uprn
self._postcode = "".join(postcode.split()).upper()
def fetch(self):
entries: list[Collection] = []
session = requests.Session()
session.headers.update(HEADERS)
form_data = {"UPRN": self._uprn}
collection_response = session.post(API_URLS["collection"], data=form_data)
# Parse HTML
soup = BeautifulSoup(collection_response.text, "html.parser")
# Find postcode
postcode = "".join(soup.find("h3").text.split()[-2:]).upper()
# Find bins and their collection details
bins = soup.find_all(class_="collection-container")
# Initialize lists to store extracted information
bin_info = []
# Extract information for each bin
for bin in bins:
bin_name = bin.find(class_="heading").text.strip()
bin_color = bin.find("img")["alt"]
collection_dates = []
collection_details = bin.find_all(class_="caption")
for detail in collection_details:
date_string = detail.text.split()[-3:]
collection_date = " ".join(date_string)
collection_dates.append(
datetime.strptime(collection_date, "%d %B %Y").date()
)
bin_info.append(
{
"Bin Name": bin_name,
"Bin Color": bin_color,
"Collection Dates": collection_dates,
}
)
# Check if the postcode matches the one provided, otherwise don't fill in the output
if postcode == self._postcode:
for info in bin_info:
entries.append(
Collection(
date=info["Collection Dates"][0],
t=info["Bin Name"],
icon=ICON_MAP.get(info["Bin Color"], "mdi:help"),
)
)
if not entries:
raise ValueError(
"Could not get collections for the given combination of UPRN and Postcode."
)
return entries

View File

@@ -0,0 +1,55 @@
# Bromsgrove District Council
Support for schedules provided by [Bromsgrove District Council](https://www.bromsgrove.gov.uk/), in the UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: bromsgrove_gov_uk
args:
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER
postcode: POSTCODE
```
### Configuration Variables
**uprn**
*(string)*
The "Unique Property Reference Number" for your address. You can find it by searching for your address at <https://www.findmyaddress.co.uk/>.
**postcode**
*(string)*
The Post Code for your address. This needs to match the postcode corresponding to your UPRN.
## Example
```yaml
waste_collection_schedule:
sources:
- name: bromsgrove_gov_uk
args:
uprn: 10094552413
postcode: B61 8DA
```
## Returned Collections
This source will return the next collection date for each container type.
## Returned collection types
### Household Collection
Grey bin is for general waste.
### Recycling Collection
Green bin is for dry recycling (metals, glass, plastics, paper and card).
### Garden waste Chargeable Collections
Brown bin if for gareden waste. This is a annual chargable service.

File diff suppressed because one or more lines are too long