Skip to content

Commit

Permalink
New Source: Melton District, UK (#3339)
Browse files Browse the repository at this point in the history
* initial commit

* test cases updated

* .md added

* undo

* .py added

* .md added

* update_docu_links
  • Loading branch information
dt215git authored Dec 30, 2024
1 parent c61f2a5 commit 28c7223
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Malvern Hills District Council](/doc/source/roundlookup_uk.md) / malvernhills.gov.uk
- [Manchester City Council](/doc/source/manchester_uk.md) / manchester.gov.uk
- [Mansfield District Council](/doc/source/mansfield_gov_uk.md) / mansfield.gov.uk
- [Melton Borough Council](/doc/source/melton_gov_uk.md) / melton.gov.uk
- [Mendip District Council](/doc/source/iweb_itouchvision_com.md) / somerset.gov.uk
- [Mid and East Antrim](/doc/source/midandeastantrim_gov_uk.md) / midandeastantrim.gov.uk
- [Mid-Sussex District Council](/doc/source/midsussex_gov_uk.md) / midsussex.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 @@ -14474,6 +14474,12 @@
"default_params": {},
"id": "mansfield_gov_uk"
},
{
"title": "Melton Borough Council",
"module": "melton_gov_uk",
"default_params": {},
"id": "melton_gov_uk"
},
{
"title": "Mendip District Council",
"module": "iweb_itouchvision_com",
Expand Down
23 changes: 23 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -15104,6 +15104,29 @@
"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_melton_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nan 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.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/melton_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"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_melton_gov_uk": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nan 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.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/melton_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"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_midandeastantrim_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/midandeastantrim_gov_uk.md",
Expand Down
23 changes: 23 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15147,6 +15147,29 @@
"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_melton_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. \n\nan 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.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/melton_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"uprn": "Unique Property Reference Number (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": "Unique Property Reference Number (UPRN)"
}
},
"reconfigure_melton_gov_uk": {
"title": "Reconfigure Source",
"description": "Configure your service provider. \n\nan 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.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/melton_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"uprn": "Unique Property Reference Number (UPRN)"
},
"data_description": {
"uprn": "Unique Property Reference Number (UPRN)"
}
},
"args_midandeastantrim_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/midandeastantrim_gov_uk.md.",
Expand Down
23 changes: 23 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -15065,6 +15065,29 @@
"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_melton_gov_uk": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nan 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.\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/melton_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"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_melton_gov_uk": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nan 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.\n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/melton_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"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_midandeastantrim_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/midandeastantrim_gov_uk.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from datetime import datetime

import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Melton Borough Council"
DESCRIPTION = "Source for waste collection services for Melton Borough Council, UK"
URL = "https://www.melton.gov.uk/"

HEADERS = {"user-agent": "Mozilla/5.0"}

HOW_TO_GET_ARGUMENTS_DESCRIPTION = {
"en": "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.",
}

PARAM_TRANSLATIONS = {
"en": {
"uprn": "Unique Property Reference Number (UPRN)",
}
}

PARAM_DESCRIPTIONS = {
"en": {
"uprn": "Unique Property Reference Number (UPRN)",
}
}

TEST_CASES = {
"Test_001": {
"uprn": "100030544791",
},
"Test_002": {
"uprn": 100030549260,
},
"Test_003": {
"uprn": "100030537000",
},
}

ICON_MAP = {
"Refuse": "mdi:trash-can",
"Recycling": "mdi:recycle",
}


class Source:
def __init__(self, uprn: str | int):
self._uprn = str(uprn)

def fetch(self) -> list[Collection]:
s = requests.Session()

params: dict = {
"id": self._uprn,
"redirect": "collections",
"rememberloc": "",
}
r = s.get(
"https://my.melton.gov.uk/set-location", headers=HEADERS, params=params
)
r.raise_for_status
soup: BeautifulSoup = BeautifulSoup(r.content, "html.parser")

entries: list = []
list_items: list = soup.find_all("li", {"class": ["dark-blue", "burgundy"]})
for item in list_items:
waste_type: str = item.find("h2").text
waste_dates: list = item.find("strong").text.split(", and then ")
for waste_date in waste_dates:
entries.append(
Collection(
date=datetime.strptime(waste_date, "%d/%m/%Y").date(),
t=waste_type,
icon=ICON_MAP.get(waste_type),
)
)

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

Support for schedules provided by [Melton Borough Council](https://www.melton.gov.uk/waste-and-recycling/), serving Melton District, UK.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: melton_gov_uk
args:
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER
```
### Configuration Variables
**uprn**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: melton_gov_uk
args:
uprn: "100030544791"
```
## How to find your `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.
`
Loading

0 comments on commit 28c7223

Please sign in to comment.