add winterthur_ch using a_region_ch Service

This commit is contained in:
5ila5
2024-08-20 17:32:03 +02:00
committed by 5ila5
parent 7986f93e2a
commit d5a4127ce5
5 changed files with 106 additions and 1 deletions

View File

@@ -1375,6 +1375,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Wald](/doc/source/a_region_ch.md) / a-region.ch
- [Waldkirch](/doc/source/a_region_ch.md) / a-region.ch
- [Waldstatt](/doc/source/a_region_ch.md) / a-region.ch
- [Winterthur](/doc/source/winterthur_ch.md) / winterthur.ch
- [Wittenbach](/doc/source/a_region_ch.md) / a-region.ch
- [Wolfhalden](/doc/source/a_region_ch.md) / a-region.ch
- [ZAKU Entsorgung](/doc/source/sammelkalender_ch.md) / zaku.ch

View File

@@ -7479,6 +7479,11 @@
"municipality": "Waldstatt"
}
},
{
"title": "Winterthur",
"module": "winterthur_ch",
"default_params": {}
},
{
"title": "Wittenbach",
"module": "a_region_ch",

View File

@@ -0,0 +1,66 @@
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.A_region_ch import (
get_region_url_by_street,
)
TITLE = "Winterthur"
DESCRIPTION = "Source for Winterthur."
URL = "https://winterthur.ch/"
TEST_CASES = {"Am Iberghang": {"street": "Am Iberghang"}}
ICON_MAP = {
"Trash": "mdi:trash-can",
"Glass": "mdi:bottle-soda",
"Bio": "mdi:leaf",
"Paper": "mdi:package-variant",
"Recycle": "mdi:recycle",
}
API_URL = "https://m.winterthur.ch/index.php?apid=1066394"
class Source:
def __init__(self, street: str):
self._street: str = street
self._ics_sources: list[Source] = []
def _get_ics_sources(self):
self._ics_sources = get_region_url_by_street(
"winterthur",
self._street,
"https://m.winterthur.ch/appl/ajax/index.php?id=street&usid=9749&do=lookupStreet&container=737670",
regex=r"(?:Tour \d{1,2} )?(.*?)(?=\s*ganze Stadt|$)",
).fetch()
for source in self._ics_sources:
r"(\d{2}\.\d{2}\.\d{4})"
def fetch(self) -> list[Collection]:
fresh_sources = False
if not self._ics_sources:
fresh_sources = True
self._get_ics_sources()
entries = []
for source in self._ics_sources:
fresh_sources, e = self._get_dates(source, fresh_sources)
entries += e
return entries
def _get_dates(self, source, fresh=False) -> tuple[bool, list[Collection]]:
exception = None
try:
entries = source.fetch()
except Exception as e:
exception = e
if exception or not entries:
if fresh:
if exception:
raise exception
return fresh, []
self._get_ics_sources()
return self._get_dates(source, fresh=True)
return fresh, entries

View File

@@ -0,0 +1,33 @@
# Winterthur
Support for schedules provided by [Winterthur](https://winterthur.ch/), serving Winterthur, Switzerland.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: winterthur_ch
args:
street: STREET (Straße)
```
### Configuration Variables
**street**
*(String) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: winterthur_ch
args:
street: Am Iberghang
```
## How to get the source argument
Find the parameter of your address using [https://m.winterthur.ch/index.php?apid=1066394](https://m.winterthur.ch/index.php?apid=1066394) and write them exactly like on the web page.

File diff suppressed because one or more lines are too long