Skip to content

Commit

Permalink
update Worthing with uprn arg
Browse files Browse the repository at this point in the history
  • Loading branch information
dt215git committed Oct 16, 2024
1 parent d6a2ade commit 2bab907
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 49 deletions.
17 changes: 11 additions & 6 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -10942,25 +10942,30 @@
},
"args_adur_worthing_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md",
"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/adur_worthing_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"address": "Addresse",
"postcode": "PLZ"
"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."
"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_adur_worthing_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/adur_worthing_gov_uk.md",
"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/adur_worthing_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"address": "Addresse",
"postcode": "PLZ"
"postcode": "PLZ",
"uprn": "UPRN"
},
"data_description": {}
"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_allerdale_gov_uk": {
"title": "Quelle konfigurieren",
Expand Down
17 changes: 11 additions & 6 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10945,25 +10945,30 @@
},
"args_adur_worthing_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.",
"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/adur_worthing_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"address": "Address",
"postcode": "Postcode"
"postcode": "Postcode",
"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."
"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_adur_worthing_gov_uk": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.",
"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/adur_worthing_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"address": "Address",
"postcode": "Postcode"
"postcode": "Postcode",
"uprn": "Unique Property Reference Number (UPRN)"
},
"data_description": {}
"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_allerdale_gov_uk": {
"title": "Configure Source",
Expand Down
17 changes: 11 additions & 6 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -10931,25 +10931,30 @@
},
"args_adur_worthing_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/adur_worthing_gov_uk.md.",
"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/adur_worthing_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"address": "Address",
"postcode": "Codice Postale CAP"
"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."
"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_adur_worthing_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/adur_worthing_gov_uk.md.",
"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/adur_worthing_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"address": "Address",
"postcode": "Codice Postale CAP"
"postcode": "Codice Postale CAP",
"uprn": "UPRN"
},
"data_description": {}
"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_allerdale_gov_uk": {
"title": "Configurazione Sorgente",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TEST_CASES = {
"Test_001": {"postcode": "BN15 9UX", "address": "1 Western Road North"},
"Test_002": {"postcode": "BN43 5WE", "address": "6 Hebe Road"},
"Test_003": {"uprn": "100062209109"},
}
HEADERS = {
"user-agent": "Mozilla/5.0",
Expand All @@ -23,47 +24,74 @@
"Refuse": "mdi:trash-can",
"Garden": "mdi:leaf",
}
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": "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",
}
}


class Source:
def __init__(self, postcode, address):
self._postcode = postcode
self._address = address
def __init__(self, postcode=None, address=None, uprn=None):
if uprn is not None:
self._uprn = uprn
self._postcode = None
self._address = None
else:
self._postcode = postcode
self._address = address
self._uprn = None

def fetch(self):
if self._postcode is None or self._address is None:
raise SourceArgumentExceptionMultiple(
["postcode", "address"],
"either postcode or address needs to be provided but neither was",
s = requests.Session()

if self._uprn is not None:
r = s.get(
f"https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address={self._uprn}",
headers=HEADERS,
)
html_collections = r.content
else:
if self._postcode is None or self._address is None:
raise SourceArgumentExceptionMultiple(
["postcode", "address"],
"either postcode or address needs to be provided but neither was",
)

s = requests.Session()
postcode_search_request = s.get(
f"https://www.adur-worthing.gov.uk/bin-day/?brlu-address-postcode={self._postcode}&return-url=/bin-day/&action=search",
headers=HEADERS,
)
html_addresses = postcode_search_request.content
addresses = bs4.BeautifulSoup(html_addresses, "html.parser")
addresses_select = addresses.find("select", {"id": "brlu-selected-address"})

postcode_search_request = s.get(
f"https://www.adur-worthing.gov.uk/bin-day/?brlu-address-postcode={self._postcode}&return-url=/bin-day/&action=search",
headers=HEADERS,
)
html_addresses = postcode_search_request.content
addresses = bs4.BeautifulSoup(html_addresses, "html.parser")
addresses_select = addresses.find("select", {"id": "brlu-selected-address"})
found_address = None
for address in addresses_select.find_all("option"):
if self._address.upper() in address.get_text().upper():
found_address = address

found_address = None
for address in addresses_select.find_all("option"):
if self._address.upper() in address.get_text().upper():
found_address = address
if found_address is None:
raise SourceArgumentNotFoundWithSuggestions(
"address",
self._address,
[a.get_text() for a in addresses_select.find_all("option")],
)

if found_address is None:
raise SourceArgumentNotFoundWithSuggestions(
"address",
self._address,
[a.get_text() for a in addresses_select.find_all("option")],
collections_request = s.get(
f"https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address={found_address['value']}&return-url=/bin-day/",
headers=HEADERS,
)
html_collections = collections_request.content

collections_request = s.get(
f"https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address={found_address['value']}&return-url=/bin-day/",
headers=HEADERS,
)
html_collections = collections_request.content
bin_collections = bs4.BeautifulSoup(html_collections, "html.parser")

bin_days_table = bin_collections.find("table", class_="bin-days")
Expand Down
23 changes: 21 additions & 2 deletions doc/source/adur_worthing_gov_uk.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ waste_collection_schedule:
args:
postcode: POSTCODE
address: FIRST LINE OF ADDRESS (X, STREET NAME)
uprn: UPRN
```
### Configuration Variables
**postcode**
*(string) (required)*
*(string) (optional)*
**address**
*(string) (required)*
*(string) (optional)*
**uprn**
*(string | integer) (optional)*
Supply both `postcode` and `address` args, or just the `uprn` arg

## Example

Expand All @@ -30,3 +37,15 @@ waste_collection_schedule:
postcode: BN15 9UX
address: 1 Western Road
```
```yaml
waste_collection_schedule:
sources:
- name: adur_worthing_gov_uk
args:
uprn: 100062209109
```

## How to get 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.

0 comments on commit 2bab907

Please sign in to comment.