mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
refactor sepan_remondis_pl
This commit is contained in:
@@ -332,8 +332,8 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
<summary>Poland</summary>
|
||||
|
||||
- [Ecoharmonogram](/doc/source/ecoharmonogram_pl.md) / ecoharmonogram.pl
|
||||
- [Poznań/Koziegłowy/Objezierze/Oborniki](/doc/source/sepan_remondis_pl.md) / sepan.remondis.pl
|
||||
- [Warsaw](/doc/source/warszawa19115_pl.md) / warszawa19115.pl
|
||||
- [Poznań/Koziegłowy/Objezierze/Oborniki](/doc/source/sepan_remondis_pl.md) / sepan.remondis.pl/harmonogram
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
import logging
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import xml.etree.ElementTree
|
||||
|
||||
import json
|
||||
import requests
|
||||
from waste_collection_schedule import Collection
|
||||
|
||||
TITLE = "Poznań/Koziegłowy/Objezierze/Oborniki"
|
||||
DESCRIPTION = "Source for Poznań/Koziegłowy/Objezierze/Oborniki city garbage collection"
|
||||
URL = "https://sepan.remondis.pl/harmonogram/"
|
||||
URL = "https://sepan.remondis.pl"
|
||||
TEST_CASES = {
|
||||
"Street Name": {"city": "Poznań", "street_name": "ŚWIĘTY MARCIN", "street_number": "1"},
|
||||
"Street Name": {
|
||||
"city": "Poznań",
|
||||
"street_name": "ŚWIĘTY MARCIN",
|
||||
"street_number": "1",
|
||||
},
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SourceConfigurationError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class SourceParseError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
PAGE_URL = "https://sepan.remondis.pl/harmonogram"
|
||||
API_URL = "https://sepan.remondis.pl/harmonogram"
|
||||
|
||||
NAME_MAP = {
|
||||
1: "Zmieszane odpady komunalne",
|
||||
@@ -46,70 +42,68 @@ ICON_MAP = {
|
||||
7: "mdi:trash-can",
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, city=None, street_name=None, street_number=None):
|
||||
if city is None or street_name is None or street_number is None:
|
||||
raise SourceConfigurationError(
|
||||
"All params city, street_name and street_number must have a value"
|
||||
)
|
||||
def __init__(self, city, street_name, street_number):
|
||||
self._city = city.upper()
|
||||
self._street_name = street_name.upper()
|
||||
self._street_number = street_number.upper()
|
||||
|
||||
def fetch(self):
|
||||
entries = []
|
||||
|
||||
url = f"{PAGE_URL}/addresses/cities"
|
||||
r = requests.get(url)
|
||||
r = requests.get(f"{API_URL}/addresses/cities")
|
||||
r.raise_for_status()
|
||||
city_id = 0
|
||||
cities = json.loads(r.text)
|
||||
for item in cities:
|
||||
if item["value"] == self._city:
|
||||
city_id = item["id"]
|
||||
if city_id == 0:
|
||||
_LOGGER.debug(f"No such city")
|
||||
return entries
|
||||
raise Exception("city not found")
|
||||
|
||||
url = f"{PAGE_URL}/addresses/streets/{city_id}"
|
||||
r = requests.get(url)
|
||||
r = requests.get(f"{API_URL}/addresses/streets/{city_id}")
|
||||
r.raise_for_status()
|
||||
street_id = 0
|
||||
streets = json.loads(r.text)
|
||||
for item in streets:
|
||||
if item["value"] == self._street_name:
|
||||
street_id = item["id"]
|
||||
if street_id == 0:
|
||||
_LOGGER.debug(f"No such street")
|
||||
return entries
|
||||
raise Exception("street not found")
|
||||
|
||||
url = f"{PAGE_URL}/addresses/numbers/{city_id}/{street_id}"
|
||||
r = requests.get(url)
|
||||
r = requests.get(f"{API_URL}/addresses/numbers/{city_id}/{street_id}")
|
||||
r.raise_for_status()
|
||||
number_id = 0
|
||||
numbers = json.loads(r.text)
|
||||
for item in numbers:
|
||||
if item["value"] == self._street_number:
|
||||
number_id = item["id"]
|
||||
if number_id == 0:
|
||||
_LOGGER.debug(f"No such number")
|
||||
return entries
|
||||
raise Exception("number not found")
|
||||
|
||||
url = f"{PAGE_URL}/reports?type=html&id={number_id}"
|
||||
r = requests.get(url)
|
||||
r = requests.get(f"{API_URL}/reports?type=html&id={number_id}")
|
||||
r.raise_for_status()
|
||||
report = json.loads(r.text)
|
||||
if report["status"] == "success":
|
||||
url = report["filePath"]
|
||||
if url == "":
|
||||
_LOGGER.debug(f"Error fetching report")
|
||||
return entries
|
||||
if report["status"] != "success":
|
||||
raise Exception("fetch report failed")
|
||||
|
||||
r = requests.get(url)
|
||||
table = r.text[r.text.find('<table'):r.text.rfind('</table>')+8]
|
||||
r = requests.get(report["filePath"])
|
||||
r.raise_for_status()
|
||||
table = r.text[r.text.find("<table") : r.text.rfind("</table>") + 8]
|
||||
tree = xml.etree.ElementTree.fromstring(table)
|
||||
year = datetime.date.today().year
|
||||
for row_index, row in enumerate(tree.findall('.//tr')):
|
||||
|
||||
entries = []
|
||||
for row_index, row in enumerate(tree.findall(".//tr")):
|
||||
if row_index > 0:
|
||||
for cell_index, cell in enumerate(row.findall('.//td')):
|
||||
for cell_index, cell in enumerate(row.findall(".//td")):
|
||||
if cell_index > 0 and isinstance(cell.text, str):
|
||||
for day in cell.text.split(','):
|
||||
entries.append(Collection(datetime.date(year, row_index-1, int(day)), NAME_MAP[cell_index], ICON_MAP[cell_index]))
|
||||
for day in cell.text.split(","):
|
||||
entries.append(
|
||||
Collection(
|
||||
datetime.date(year, row_index - 1, int(day)),
|
||||
NAME_MAP[cell_index],
|
||||
ICON_MAP[cell_index],
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
|
||||
@@ -21,13 +21,13 @@ waste_collection_schedule:
|
||||
### Configuration Variables
|
||||
|
||||
**city**
|
||||
*(string)*
|
||||
*(string) (required)*
|
||||
|
||||
**street_address**
|
||||
*(string)*
|
||||
*(string) (required)*
|
||||
|
||||
**street_number**
|
||||
*(string)*
|
||||
*(string)(required)*
|
||||
|
||||
All arguments must be provided.
|
||||
|
||||
|
||||
2
info.md
2
info.md
@@ -25,7 +25,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 Wallre, Gemeente Westland, HVC Groep, Meerlanden, Mijn Blink, PreZero, Purmerend, RAD BV, Reinigingsbedrijf Midden Nederland, Reinis, Spaarne Landen, Stadswerk 072, Twente Milieu, Waardlanden, Ximmio, ZRD |
|
||||
| New Zealand | Auckland Council, Christchurch City Council, Gore, Invercargill & Southland, Horowhenua District Council, Waipa District Council, Wellington City Council |
|
||||
| Norway | Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Stavanger Kommune |
|
||||
| Poland | Ecoharmonogram, Warsaw, Poznań/Koziegłowy/Objezierze/Oborniki |
|
||||
| Poland | Ecoharmonogram, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw |
|
||||
| Slovenia | Moji odpadki, Ljubljana |
|
||||
| Sweden | Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, Ronneby Miljöteknik, SRV Återvinning, SSAM, Sysav Sophämntning, VA Syd Sophämntning |
|
||||
| Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, 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