mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
Add Pronatura Bydgoszcz (#2138)
* Add Pronatura Bydgoszcz * follow contribution guide, clean code, address PR comments * rename + minor changes pronatura_bydgoszcz rename to match URL (add _pl) removed unnecessary method get_data NAME_MAP[waste_type] and ICON_MAP[waste_type] with get equivalents to prevent failour on name change modified md file to be more in line with other sources --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
@@ -1129,6 +1129,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
<details>
|
||||
<summary>Poland</summary>
|
||||
|
||||
- [Bydgoszcz Pronatura](/doc/source/pronatura_bydgoszcz_pl.md) / pronatura.bydgoszcz.pl
|
||||
- [Ecoharmonogram](/doc/source/ecoharmonogram_pl.md) / ecoharmonogram.pl
|
||||
- [Gmina Miękinia](/doc/source/gmina_miekinia_pl.md) / api.skycms.com.pl
|
||||
- [Poznań/Koziegłowy/Objezierze/Oborniki](/doc/source/sepan_remondis_pl.md) / sepan.remondis.pl
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "Bydgoszcz Pronatura"
|
||||
DESCRIPTION = "Source for Bydgoszcz city garbage collection by Pronatura"
|
||||
URL = "http://www.pronatura.bydgoszcz.pl/"
|
||||
API_URL = "https://zs5cv4ng75.execute-api.eu-central-1.amazonaws.com/prod"
|
||||
COUNTRY = "pl"
|
||||
TEST_CASES = {
|
||||
"Case1": {
|
||||
"street_name": "LEGNICKA",
|
||||
"street_number": 1,
|
||||
},
|
||||
"Case2": {
|
||||
"street_name": "JÓZEFA SOWIŃSKIEGO",
|
||||
"street_number": "22A",
|
||||
},
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
NAME_MAP = {
|
||||
"odpady zmieszane": "Zmieszane odpady komunalne",
|
||||
"papier": "Papier",
|
||||
"plastik": "Metale i tworzywa sztuczne",
|
||||
"szkło": "Szkło",
|
||||
"odpady bio": "Bioodpady",
|
||||
"odpady wielkogabarytowe": "Odpady wielkogabarytowe",
|
||||
}
|
||||
|
||||
ICON_MAP = {
|
||||
"odpady zmieszane": "mdi:trash-can",
|
||||
"papier": "mdi:recycle",
|
||||
"plastik": "mdi:recycle",
|
||||
"szkło": "mdi:recycle",
|
||||
"odpady bio": "mdi:leaf",
|
||||
"odpady wielkogabarytowe": "mdi:wardrobe",
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, street_name, street_number):
|
||||
self._street_name = street_name.upper()
|
||||
self._street_number = str(street_number).upper()
|
||||
|
||||
def fetch(self):
|
||||
streets_url = f"{API_URL}/streets"
|
||||
r = requests.get(streets_url)
|
||||
r.raise_for_status()
|
||||
streets = json.loads(r.text)
|
||||
street_id = None
|
||||
for street in streets:
|
||||
if street["street"].upper() == self._street_name:
|
||||
street_id = street["id"]
|
||||
break
|
||||
if street_id is None:
|
||||
raise Exception("Street not found")
|
||||
|
||||
addresses_url = f"{API_URL}/address-points/{street_id}"
|
||||
r = requests.get(addresses_url)
|
||||
r.raise_for_status()
|
||||
addresses = json.loads(r.text)
|
||||
address_id = None
|
||||
for address in addresses:
|
||||
if address["buildingNumber"].upper() == self._street_number:
|
||||
address_id = address["id"]
|
||||
break
|
||||
if address_id is None:
|
||||
raise Exception("Address not found")
|
||||
|
||||
schedule_url = f"{API_URL}/trash-schedule/{address_id}"
|
||||
r = requests.get(schedule_url)
|
||||
r.raise_for_status()
|
||||
schedule = json.loads(r.text)
|
||||
trash_schedule = schedule["trashSchedule"]
|
||||
|
||||
entries = []
|
||||
year = schedule["year"]
|
||||
for month_schedule in trash_schedule:
|
||||
month = self._get_month_number(month_schedule["month"])
|
||||
for collection in month_schedule["schedule"]:
|
||||
waste_type = collection["type"]
|
||||
for day in collection["days"]:
|
||||
entries.append(
|
||||
Collection(
|
||||
datetime.date(year, month, int(day)),
|
||||
NAME_MAP.get(waste_type, waste_type),
|
||||
ICON_MAP.get(waste_type),
|
||||
)
|
||||
)
|
||||
return entries
|
||||
|
||||
def _get_month_number(self, month_name):
|
||||
month_map = {
|
||||
"Styczeń": 1,
|
||||
"Luty": 2,
|
||||
"Marzec": 3,
|
||||
"Kwiecień": 4,
|
||||
"Maj": 5,
|
||||
"Czerwiec": 6,
|
||||
"Lipiec": 7,
|
||||
"Sierpień": 8,
|
||||
"Wrzesień": 9,
|
||||
"Październik": 10,
|
||||
"Listopad": 11,
|
||||
"Grudzień": 12,
|
||||
}
|
||||
return month_map[month_name]
|
||||
35
doc/source/pronatura_bydgoszcz_pl.md
Normal file
35
doc/source/pronatura_bydgoszcz_pl.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Pronatura Bydgoszcz
|
||||
|
||||
Support for schedules provided by [Pronatura Bydgoszcz](http://www.pronatura.bydgoszcz.pl/), serving Bydgoszcz, Poland.
|
||||
|
||||
There are other companies providing garbage collection services in Bydgoszcz (Remondis and Corimp) but this source does not support them.
|
||||
|
||||
To check which provider you have, visit this page at [Czysta Bydgoszcz](https://www.czystabydgoszcz.pl/odpady-komunalne/podzial-na-sektory/).
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: pronatura_bydgoszcz_pl
|
||||
args:
|
||||
street_name: STREET_NAME
|
||||
street_number: STREET_NUMBER
|
||||
```
|
||||
|
||||
**street_name**
|
||||
*(string) (required)*
|
||||
|
||||
**street_number**
|
||||
*(string|integer) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: pronatura_bydgoszcz_pl
|
||||
args:
|
||||
street_name: JÓZEFA SOWIŃSKIEGO
|
||||
street_number: 22A
|
||||
```
|
||||
2
info.md
2
info.md
@@ -32,7 +32,7 @@ Waste collection schedules from service provider web sites are updated daily, de
|
||||
| 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 |
|
||||
| New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Hutt City Council, Tauranga City Council, Waipa District Council, Wellington City Council |
|
||||
| Norway | BIR (Bergensområdets Interkommunale Renovasjonsselskap), IRiS, Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Sandnes Kommune, Stavanger Kommune, Trondheim |
|
||||
| Poland | Ecoharmonogram, Gmina Miękinia, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław |
|
||||
| Poland | Bydgoszcz Pronatura, Ecoharmonogram, Gmina Miękinia, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław |
|
||||
| Slovenia | Moji odpadki, Ljubljana |
|
||||
| Sweden | Affärsverken, Gästrike Återvinnare, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Lund Waste Collection, North / Middle Bohuslän - Rambo AB, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning, VIVAB Sophämtning |
|
||||
| Switzerland | A-Region, Alchenstorf, Andwil, Appenzell, Berg, Bühler, Canton of Zürich, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Münsingen BE, Switzerland, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
|
||||
|
||||
Reference in New Issue
Block a user