mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
@@ -1,5 +1,7 @@
|
||||
import logging
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from xml.dom.minidom import parseString
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
from waste_collection_schedule.service.ICS import ICS
|
||||
|
||||
@@ -8,17 +10,33 @@ DESCRIPTION = "Source for Umweltprofis"
|
||||
URL = "https://www.umweltprofis.at"
|
||||
TEST_CASES = {
|
||||
"Ebensee": {"url": "https://data.umweltprofis.at/OpenData/AppointmentService/AppointmentService.asmx/GetIcalWastePickupCalendar?key=KXX_K0bIXDdk0NrTkk3xWqLM9-bsNgIVBE6FMXDObTqxmp9S39nIqwhf9LTIAX9shrlpfCYU7TG_8pS9NjkAJnM_ruQ1SYm3V9YXVRfLRws1"},
|
||||
"Rohrbach": {"xmlurl": "https://data.umweltprofis.at/opendata/AppointmentService/AppointmentService.asmx/GetTermineForLocationSecured?Key=TEMPKeyabvvMKVCic0cMcmsTEMPKey&StreetNr=118213&HouseNr=Alle&intervall=Alle"},
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def getText(element):
|
||||
s = ""
|
||||
for e in element.childNodes:
|
||||
if e.nodeType == e.TEXT_NODE:
|
||||
s += e.nodeValue
|
||||
return s
|
||||
|
||||
class Source:
|
||||
def __init__(self, url):
|
||||
def __init__(self, url=None, xmlurl=None):
|
||||
self._url = url
|
||||
self._xmlurl = xmlurl
|
||||
self._ics = ICS()
|
||||
if url is None and xmlurl is None:
|
||||
raise Exception("either url or xmlurl needs to be specified")
|
||||
|
||||
def fetch(self):
|
||||
if self._url is not None:
|
||||
return self.fetch_ics()
|
||||
elif self._xmlurl is not None:
|
||||
return self.fetch_xml()
|
||||
|
||||
def fetch_ics(self):
|
||||
r = requests.get(self._url)
|
||||
if r.status_code != 200:
|
||||
_LOGGER.error("Error querying calendar data")
|
||||
@@ -32,3 +50,18 @@ class Source:
|
||||
for d in dates:
|
||||
entries.append(Collection(d[0], d[1]))
|
||||
return entries
|
||||
|
||||
def fetch_xml(self):
|
||||
r = requests.get(self._xmlurl)
|
||||
r.raise_for_status()
|
||||
|
||||
doc = parseString(r.text)
|
||||
appointments = doc.getElementsByTagName("AppointmentEntry")
|
||||
|
||||
entries = []
|
||||
for a in appointments:
|
||||
date_string = getText(a.getElementsByTagName("Datum")[0])
|
||||
date = datetime.fromisoformat(date_string).date()
|
||||
waste_type = getText(a.getElementsByTagName("WasteType")[0])
|
||||
entries.append(Collection(date, waste_type))
|
||||
return entries
|
||||
|
||||
@@ -4,20 +4,21 @@ Support for schedules provided by [Umweltprofis.at](https://www.umweltprofis.at)
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
You need to generate your personal iCal Link before you can start using this source. Go to [https://data.umweltprofis.at/opendata/AppointmentService/index.aspx](https://data.umweltprofis.at/opendata/AppointmentService/index.aspx) and fill out the form. At the end, you can generate an iCal link. Copy this link and paste it to configuration.yaml as seen below.
|
||||
You need to generate your personal XML link before you can start using this source. Go to [https://data.umweltprofis.at/opendata/AppointmentService/index.aspx](https://data.umweltprofis.at/opendata/AppointmentService/index.aspx) and fill out the form. At the end
|
||||
at step 6 you get a link to a XML file. Copy this link and paste it to configuration.yaml as seen below.
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: data_umweltprofis_at
|
||||
args:
|
||||
url: URL
|
||||
xmlurl: URL
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**URL**<br>
|
||||
*(url) (required)*
|
||||
**xmlurl**<br>
|
||||
*(URL) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
@@ -26,5 +27,5 @@ waste_collection_schedule:
|
||||
sources:
|
||||
- name: data_umweltprofis_at
|
||||
args:
|
||||
url: https://data.umweltprofis.at/OpenData/AppointmentService/AppointmentService.asmx/GetIcalWastePickupCalendar?key=xxx
|
||||
xmlurl: https://data.umweltprofis.at/opendata/AppointmentService/AppointmentService.asmx/GetTermineForLocationSecured?Key=TEMPKeyabvvMKVCic0cMcmsTEMPKey&StreetNr=124972&HouseNr=Alle&intervall=Alle
|
||||
```
|
||||
Reference in New Issue
Block a user