Skip to content

Commit

Permalink
Add Norwich City Council source (#3631)
Browse files Browse the repository at this point in the history
* Add Norwich City Coucil

* reformatting

---------

Co-authored-by: 5ila5 <[email protected]>
  • Loading branch information
nathforge and 5ila5 authored Jan 19, 2025
1 parent fd01d80 commit de87e35
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [North Yorkshire Council - Harrogate](/doc/source/northyorks_harrogate_gov_uk.md) / secure.harrogate.gov.uk
- [North Yorkshire Council - Scarborough](/doc/source/northyorks_scarborough_gov_uk.md) / northyorks.gov.uk
- [North Yorkshire Council - Selby](/doc/source/northyorks_selby_gov_uk.md) / northyorks.gov.uk
- [Norwich City Council](/doc/source/norwich_gov_uk.md) / norwich.gov.uk
- [Nottingham City Council](/doc/source/nottingham_city_gov_uk.md) / nottinghamcity.gov.uk
- [Oadby and Wigston Council](/doc/source/oadby_wigston_gov_uk.md) / oadby-wigston.gov.uk
- [Oldham Council](/doc/source/oldham_gov_uk.md) / oldham.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 @@ -14697,6 +14697,12 @@
"default_params": {},
"id": "northyorks_selby_gov_uk"
},
{
"title": "Norwich City Council",
"module": "norwich_gov_uk",
"default_params": {},
"id": "norwich_gov_uk"
},
{
"title": "Nottingham City Council",
"module": "nottingham_city_gov_uk",
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 @@ -15943,6 +15943,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_norwich_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/norwich_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_norwich_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/norwich_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_nottingham_city_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nottingham_city_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 @@ -16001,6 +16001,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_norwich_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/norwich_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"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_norwich_gov_uk": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/norwich_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"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_nottingham_city_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nottingham_city_gov_uk.md.",
Expand Down
23 changes: 23 additions & 0 deletions custom_components/waste_collection_schedule/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -15894,6 +15894,29 @@
"uprn": "Une manière simple de retrouver votre numéro unique de propriété (UPRN) est de vous rendre sur https://www.findmyaddress.co.uk/ et de saisir les détails de votre adresse."
}
},
"args_norwich_gov_uk": {
"title": "Configurer la Source",
"description": "Configurez votre fournisseur de services. Plus de détails : https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/norwich_gov_uk.md.",
"data": {
"calendar_title": "Titre du Calendrier",
"uprn": "UPRN"
},
"data_description": {
"calendar_title": "Un nom plus lisible ou convivial pour le calendrier des déchets. Si aucun n'est fourni, le nom renvoyé par la source sera utilisé.",
"uprn": "Une manière simple de retrouver votre numéro unique de propriété (UPRN) est de vous rendre sur https://www.findmyaddress.co.uk/ et de saisir les détails de votre adresse."
}
},
"reconfigure_norwich_gov_uk": {
"title": "Reconfigurer la Source",
"description": "Configurez votre fournisseur de services. Plus de détails : https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/norwich_gov_uk.md.",
"data": {
"calendar_title": "Titre du Calendrier",
"uprn": "UPRN"
},
"data_description": {
"uprn": "Une manière simple de retrouver votre numéro unique de propriété (UPRN) est de vous rendre sur https://www.findmyaddress.co.uk/ et de saisir les détails de votre adresse."
}
},
"args_nottingham_city_gov_uk": {
"title": "Configurer la Source",
"description": "Configurez votre fournisseur de services. Plus de détails : https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nottingham_city_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 @@ -15901,6 +15901,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_norwich_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/norwich_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_norwich_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/norwich_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_nottingham_city_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/nottingham_city_gov_uk.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import datetime
import re

import requests
from waste_collection_schedule import Collection

TITLE = "Norwich City Council"
DESCRIPTION = "Source for norwich.gov.uk"
URL = "https://www.norwich.gov.uk"
TEST_CASES = {
"1 Stuart Road": {"uprn": "100090924499"},
}

API_URL = "https://maps.norwich.gov.uk/arcgis/rest/services/MyNorwich/PropertyDetails/FeatureServer/3/query"
COLLECTION_TYPES = {
"waste and food waste": {
"title": "Waste and Food Waste",
"icon": "mdi:trash-can",
},
"recycling and food waste": {
"title": "Recycling and Food Waste",
"icon": "mdi:recycle",
},
}


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

def fetch(self) -> list[Collection]:
params = {
"f": "json",
"where": f"UPRN='{self._uprn}' or UPRN='0{self._uprn}'",
"outFields": "WasteCollectionHtml",
}
response = requests.get(API_URL, params=params)
response.raise_for_status()

features = response.json()["features"]

if len(features) != 1:
raise Exception(f"Expected 1 feature, got {len(features)}")

html = features[0]["attributes"]["WasteCollectionHtml"]

date_match = re.search(r"Your next collection: <strong>(.*?)</strong>", html)
if not date_match:
raise Exception("No collection date found")
date_str = date_match.group(1)
type_match = re.search(r"We will be collecting: <strong>(.*?).</strong>", html)
if not type_match:
raise Exception("No collection type found")
type_str = type_match.group(1)

date = datetime.datetime.strptime(date_str, "%d/%m/%Y").date()

type = COLLECTION_TYPES.get(type_str) or {}

entries = [
Collection(
date=date,
t=type["title"],
icon=type["icon"],
),
]

return entries
34 changes: 34 additions & 0 deletions doc/source/norwich_gov_uk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# North Norfolk District Council

Support for the next collection day provided by [Norwich City Council](https://maps.norwich.gov.uk/mynorwich/), serving Norwich, UK.

Note that Norwich City Council does not provide a schedule, only the next collection day.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: norwich_gov_uk
args:
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER
```

### Configuration Variables

**uprn**
*(string) (required)*

## Example

```yaml
waste_collection_schedule:
sources:
- name: norwich_gov_uk
args:
uprn: "100090924499"
```

## 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 de87e35

Please sign in to comment.