Skip to content

Commit

Permalink
add Rochdale, UK
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Oct 4, 2024
1 parent 4eedd1e commit 1d3e00b
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Renfrewshire Council](/doc/source/renfrewshire_gov_uk.md) / renfrewshire.gov.uk
- [Rhondda Cynon Taf County Borough Council](/doc/source/rctcbc_gov_uk.md) / rctcbc.gov.uk
- [Richmondshire District Council](/doc/source/richmondshire_gov_uk.md) / richmondshire.gov.uk
- [Rochdale Borough Council](/doc/source/rochdale_gov_uk.md) / rochdale.gov.uk
- [Rotherham](/doc/source/apps_imactivate_com.md) / rotherham.gov.uk
- [Rotherham Metropolitan Borough Council](/doc/source/rotherham_gov_uk.md) / rotherham.gov.uk
- [Runnymede Borough Council](/doc/source/runnymede_gov_uk.md) / runnymede.gov.uk
Expand Down
6 changes: 6 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -11278,6 +11278,12 @@
"default_params": {},
"id": "richmondshire_gov_uk"
},
{
"title": "Rochdale Borough Council",
"module": "rochdale_gov_uk",
"default_params": {},
"id": "rochdale_gov_uk"
},
{
"title": "Rotherham",
"module": "apps_imactivate_com",
Expand Down
25 changes: 25 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -14343,6 +14343,31 @@
"uprn": "Eine einfache Möglichkeit, Ihre Unique Property Reference Number (UPRN) zu finden, besteht darin, auf https://www.findmyaddress.co.uk/ zu gehen und Ihre Adressdaten einzugeben."
}
},
"args_rochdale_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rochdale_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"postcode": "PLZ",
"uprn": "UPRN"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet.",
"uprn": "Eine einfache Möglichkeit, Ihre Unique Property Reference Number (UPRN) zu finden, besteht darin, auf https://www.findmyaddress.co.uk/ zu gehen und Ihre Adressdaten einzugeben."
}
},
"reconfigure_rochdale_gov_uk": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rochdale_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"postcode": "PLZ",
"uprn": "UPRN"
},
"data_description": {
"uprn": "Eine einfache Möglichkeit, Ihre Unique Property Reference Number (UPRN) zu finden, besteht darin, auf https://www.findmyaddress.co.uk/ zu gehen und Ihre Adressdaten einzugeben."
}
},
"args_rotherham_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rotherham_gov_uk.md",
Expand Down
25 changes: 25 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14346,6 +14346,31 @@
"uprn": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details."
}
},
"args_rochdale_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rochdale_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"postcode": "Postcode",
"uprn": "UPRN"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used.",
"uprn": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details."
}
},
"reconfigure_rochdale_gov_uk": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rochdale_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"postcode": "Postcode",
"uprn": "UPRN"
},
"data_description": {
"uprn": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details."
}
},
"args_rotherham_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rotherham_gov_uk.md.",
Expand Down
25 changes: 25 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -14332,6 +14332,31 @@
"uprn": "Un modo facile per scoprire il tuo Numero di Riferimento Proprietà Unica (UPRN) è andare su https://www.findmyaddress.co.uk/ e inserire i dettagli del tuo indirizzo."
}
},
"args_rochdale_gov_uk": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rochdale_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"postcode": "Codice Postale CAP",
"uprn": "UPRN"
},
"data_description": {
"calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi.",
"uprn": "Un modo facile per scoprire il tuo Numero di Riferimento Proprietà Unica (UPRN) è andare su https://www.findmyaddress.co.uk/ e inserire i dettagli del tuo indirizzo."
}
},
"reconfigure_rochdale_gov_uk": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rochdale_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"postcode": "Codice Postale CAP",
"uprn": "UPRN"
},
"data_description": {
"uprn": "Un modo facile per scoprire il tuo Numero di Riferimento Proprietà Unica (UPRN) è andare su https://www.findmyaddress.co.uk/ e inserire i dettagli del tuo indirizzo."
}
},
"args_rotherham_gov_uk": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/rotherham_gov_uk.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import requests
from bs4 import BeautifulSoup
from dateutil.parser import parse
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.exceptions import (
SourceArgumentNotFound,
SourceArgumentNotFoundWithSuggestions,
)

TITLE = "Rochdale Borough Council"
DESCRIPTION = "Source for Rochdale Borough Council."
URL = "https://www.rochdale.gov.uk/"
TEST_CASES = {
"144 Claybank Street, Heywood": {"postcode": "OL104TJ", "uprn": 10094359340},
"OL12 7TX 23030658": {"postcode": "OL12 7TX", "uprn": "23030658"},
}


ICON_MAP = {
"Food": "mdi:leaf",
"Paper": "mdi:package-variant",
"Rubbish": "mdi:trash-can",
"Cans": "mdi:bottle-soda",
}


API_URL = "https://webforms.rochdale.gov.uk/BinCalendar"


class Source:
def __init__(self, postcode: str, uprn: str | int):
self._postcode: str = postcode.replace(" ", "").upper()
self._uprn: str | int = uprn

def fetch(self) -> list[Collection]:
data = {
"FormTypeId": "2",
"Step": "2",
"PostCode": self._postcode,
"SelectedUprn": self._uprn,
}

r = requests.post(API_URL, data=data)
r.raise_for_status()

soup = BeautifulSoup(r.text, "html.parser")
table = soup.select_one("table#tblCollectionDetails")
if not table:
# ERROR STATE: Check if the postcode or UPRN is invalid
uprn_options = list(soup.select("select#SelectedUprn > option"))
uprn_options = list(
filter(
lambda option: option.attrs.get("value")
and option.attrs["value"].isdigit(),
uprn_options,
)
)
if not uprn_options:
raise SourceArgumentNotFound("postcode", self._postcode)
uprns = [option.attrs["value"] for option in uprn_options]
raise SourceArgumentNotFoundWithSuggestions("uprn", self._uprn, uprns)

body = table.select_one("tbody")
if not body:
raise Exception("Could not find Collection table body")

entries = []
for row in body.select("tr"):
date = None
for idx, cell in enumerate(row.select("th, td")):
if idx == 0: # Date Column
date = parse(cell.text, dayfirst=True).date()
coll_type_div = cell.select_one("div")
if not coll_type_div or date is None:
continue
coll_type = coll_type_div.attrs.get("data-label")
if not isinstance(coll_type, str):
continue
icon = ICON_MAP.get(coll_type.split()[0])

entries.append(Collection(date=date, t=coll_type, icon=icon))

return entries
40 changes: 40 additions & 0 deletions doc/source/rochdale_gov_uk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Rochdale Borough Council

Support for schedules provided by [Rochdale Borough Council](https://www.rochdale.gov.uk/), serving Rochdale, UK.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: rochdale_gov_uk
args:
postcode: POSTCODE
uprn: "UPRN"

```
### Configuration Variables
**postcode**
*(String) (required)*
**uprn**
*(String | Integer) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: rochdale_gov_uk
args:
postcode: OL104TJ
uprn: "10094359340"
```
## How to get the source argument
Use your postcode as the `postcode` argument and your Unique Property Reference Number (UPRN) as the `uprn` argument.

An easy way to discover your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering in your address details.
Loading

0 comments on commit 1d3e00b

Please sign in to comment.