mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
Add Rotorua lakes council (NZ) source (#2348)
* added rotorua lakes council source * added Rotorua lakes council source, updated README.md and added a rotorua_lakes_council_nz.md * Update rotorua_lakes_council_nz.py Removed debug print statement * Removed geopy dependency - replaced with direct calls to OSM (nominatim) Added logger and removed print statements * Simplified output to "Recycling" and "Rubbish" * Split rubbish and recycling outputs for days that both bin types are collected * refactoring + reformatting + ./update_docu_links.py * ./update_docu_links.py --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com> Co-authored-by: 5ila5 <38183212+5ila5@users.noreply.github.com>
This commit is contained in:
@@ -1167,6 +1167,7 @@ If your service provider is not listed, feel free to open a [source request issu
|
||||
- [Horowhenua District Council](/doc/source/horowhenua_govt_nz.md) / horowhenua.govt.nz
|
||||
- [Hutt City Council](/doc/source/toogoodtowaste_co_nz.md) / toogoodtowaste.co.nz
|
||||
- [Porirua City](/doc/source/poriruacity_govt_nz.md) / poriruacity.govt.nz
|
||||
- [Rotorua Lakes Council](/doc/source/rotorua_lakes_council_nz.md) / rotorualakescouncil.nz
|
||||
- [Tauranga City Council](/doc/source/tauranga_govt_nz.md) / tauranga.govt.nz
|
||||
- [Waipa District Council](/doc/source/waipa_nz.md) / waipadc.govt.nz
|
||||
- [Wellington City Council](/doc/source/wellington_govt_nz.md) / wellington.govt.nz
|
||||
|
||||
@@ -6280,6 +6280,11 @@
|
||||
"module": "poriruacity_govt_nz",
|
||||
"default_params": {}
|
||||
},
|
||||
{
|
||||
"title": "Rotorua Lakes Council",
|
||||
"module": "rotorua_lakes_council_nz",
|
||||
"default_params": {}
|
||||
},
|
||||
{
|
||||
"title": "Tauranga City Council",
|
||||
"module": "tauranga_govt_nz",
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TITLE = "Rotorua Lakes Council"
|
||||
DESCRIPTION = "Source for Rotorua Lakes Council"
|
||||
URL = "https://www.rotorualakescouncil.nz"
|
||||
API_URL = (
|
||||
"https://gis.rdc.govt.nz/server/rest/services/Core/RdcServices/MapServer/125/query"
|
||||
)
|
||||
ICON_MAP = {
|
||||
"Rubbish": "mdi:trash-can",
|
||||
"Recycling": "mdi:recycle",
|
||||
}
|
||||
HEADERS = {"User-Agent": "waste-collection-schedule"}
|
||||
|
||||
TEST_CASES = {
|
||||
"Test1": {"address": "1061 Haupapa Street"},
|
||||
"Test2": {"address": "369 state highway 33"},
|
||||
"Test3": {"address": "17 Tihi road"},
|
||||
"Test4": {"address": "12a robin st"},
|
||||
"Test5": {"address": "25 kaska rd"},
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, address):
|
||||
self._address = address
|
||||
|
||||
def fetch_coordinates(self):
|
||||
params = {
|
||||
"format": "json",
|
||||
"q": self._address,
|
||||
}
|
||||
try:
|
||||
response = requests.get(
|
||||
"https://nominatim.openstreetmap.org/search",
|
||||
params=params,
|
||||
headers=HEADERS,
|
||||
timeout=10,
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
if not data:
|
||||
raise ValueError(f"Geolocation failed for address: {self._address}")
|
||||
return float(data[0]["lat"]), float(data[0]["lon"])
|
||||
except Exception as e:
|
||||
raise ValueError(
|
||||
f"Geolocation failed for address: {self._address} with error: {e}"
|
||||
)
|
||||
|
||||
def fetch(self):
|
||||
lat, lon = self.fetch_coordinates()
|
||||
|
||||
params = {
|
||||
"f": "json",
|
||||
"geometryType": "esriGeometryPoint",
|
||||
"geometry": f"{lon},{lat}",
|
||||
"inSR": 4326,
|
||||
"spatialRel": "esriSpatialRelIntersects",
|
||||
"outFields": "OBJECTID,Name,Collection,Day,FN,Label1,Label2",
|
||||
"outSR": 4326,
|
||||
}
|
||||
try:
|
||||
response = requests.get(API_URL, params=params, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except requests.RequestException as e:
|
||||
raise ValueError(f"API request failed: {e}")
|
||||
|
||||
entries = []
|
||||
for feature in data.get("features", []):
|
||||
attributes = feature.get("attributes", {})
|
||||
schedule_html = attributes.get("Collection", "")
|
||||
|
||||
if not schedule_html:
|
||||
_LOGGER.warning(f"No schedule HTML found in attributes: {attributes}")
|
||||
continue
|
||||
|
||||
soup = BeautifulSoup(schedule_html, "html.parser")
|
||||
list_items = soup.find_all("li")
|
||||
|
||||
if not list_items:
|
||||
_LOGGER.warning(
|
||||
f"No list items found in schedule HTML: {schedule_html}"
|
||||
)
|
||||
continue
|
||||
|
||||
for item in list_items:
|
||||
collection_type_tag = item.find("b")
|
||||
collection_type_text = (
|
||||
collection_type_tag.get_text().strip()
|
||||
if collection_type_tag
|
||||
else "Unknown"
|
||||
)
|
||||
collection_type_text = collection_type_text.removesuffix("only").strip()
|
||||
|
||||
br_tag = item.find("br")
|
||||
if br_tag and br_tag.next_sibling:
|
||||
date_str = br_tag.next_sibling.strip()
|
||||
|
||||
try:
|
||||
date = datetime.datetime.strptime(
|
||||
date_str, "%A %d %b %Y"
|
||||
).date()
|
||||
except ValueError:
|
||||
_LOGGER.error(f"Date parsing error for value: {date_str}")
|
||||
continue
|
||||
|
||||
for bin_type in collection_type_text.split(" and "):
|
||||
bin_type = bin_type.strip().capitalize()
|
||||
entries.append(
|
||||
Collection(
|
||||
date=date,
|
||||
t=bin_type,
|
||||
icon=ICON_MAP.get(bin_type),
|
||||
)
|
||||
)
|
||||
|
||||
if not entries:
|
||||
raise ValueError(
|
||||
f"No collection entries found for address: {self._address}"
|
||||
)
|
||||
|
||||
return entries
|
||||
36
doc/source/rotorua_lakes_council_nz.md
Normal file
36
doc/source/rotorua_lakes_council_nz.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Rotorua Lakes Council
|
||||
|
||||
[Source URL](https://rotorua.maps.arcgis.com/apps/webappviewer/index.html?id=7176f71a4ca34c16aa7dc7f942b919d5)
|
||||
|
||||
[API URL](https://gis.rdc.govt.nz/server/rest/services/Core/RdcServices/MapServer/125/query)
|
||||
|
||||
This source provides waste collection schedules for Rotorua Lakes Council. It uses the Rotorua Lakes Council's GIS API to fetch waste collection schedules based on the provided address.
|
||||
|
||||
## Configuration via `configuration.yaml`
|
||||
|
||||
To configure the source, add the following to your `configuration.yaml` file:
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: rotorua_lakes_council_nz
|
||||
args:
|
||||
address: UNIQUE_ADDRESS
|
||||
```
|
||||
|
||||
## Configuration Variables
|
||||
|
||||
**address** (string) (required)
|
||||
The address for which you want to retrieve the waste collection schedule.
|
||||
|
||||
## Example
|
||||
|
||||
An example configuration:
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: rotorua_lakes_council_nz
|
||||
args:
|
||||
address: 1061 Haupapa St
|
||||
```
|
||||
2
info.md
2
info.md
@@ -30,7 +30,7 @@ Waste collection schedules from service provider web sites are updated daily, de
|
||||
| Lithuania | Kauno švara, Telšių keliai |
|
||||
| Luxembourg | Esch-sur-Alzette |
|
||||
| Netherlands | ACV Group, Alpen an den Rijn, Area Afval, Avalex, Avri, Bar Afvalbeheer, Circulus, Cyclus NV, Dar, Den Haag, GAD, Gemeente Almere, Gemeente Berkelland, Gemeente Cranendonck, Gemeente Hellendoorn, Gemeente Lingewaard, Gemeente Meppel, Gemeente Middelburg + Vlissingen, Gemeente Peel en Maas, Gemeente Schouwen-Duiveland, Gemeente Sudwest-Fryslan, Gemeente Venray, Gemeente Voorschoten, Gemeente Waalre, Gemeente Westland, HVC Groep, Meerlanden, Mijn Blink, PreZero, Purmerend, RAD BV, Reinis, Spaarnelanden, Twente Milieu, Waardlanden, Ximmio, ZRD, Ôffalkalinder van Noardeast-Fryslân & Dantumadiel |
|
||||
| New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Hutt City Council, Porirua City, Tauranga City Council, Waipa District Council, Wellington City Council |
|
||||
| New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Hutt City Council, Porirua City, Rotorua Lakes Council, Tauranga City Council, Waipa District Council, Wellington City Council |
|
||||
| Norway | BIR (Bergensområdets Interkommunale Renovasjonsselskap), Fosen Renovasjon, IRiS, Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Sandnes Kommune, Stavanger Kommune, Trondheim |
|
||||
| Poland | Bydgoszcz Pronatura, Ecoharmonogram, Gmina Miękinia, Koziegłowy/Objezierze/Oborniki, Poznań, Warsaw, Wrocław |
|
||||
| Slovenia | Moji odpadki, Ljubljana |
|
||||
|
||||
Reference in New Issue
Block a user