refactor muenchenstein_ch

This commit is contained in:
mampfes
2023-01-15 10:55:49 +01:00
parent 4a1da4c60f
commit a6dc302524
4 changed files with 55 additions and 9 deletions

View File

@@ -320,6 +320,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Lutzenberg](/doc/source/a_region_ch.md) / a-region.ch
- [Muolen](/doc/source/a_region_ch.md) / a-region.ch
- [Mörschwil](/doc/source/a_region_ch.md) / a-region.ch
- [Münchenstein](/doc/source/muenchenstein_ch.md) / muenchenstein.ch
- [Rehetobel](/doc/source/a_region_ch.md) / a-region.ch
- [Rorschach](/doc/source/a_region_ch.md) / a-region.ch
- [Rorschacherberg](/doc/source/a_region_ch.md) / a-region.ch

View File

@@ -5,16 +5,18 @@ import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Abfallsammlung Münchenstein"
TITLE = "Münchenstein"
DESCRIPTION = "Source for Muenchenstein waste collection."
URL = "https://www.muenchenstein.ch/abfuhrdaten"
URL = "https://www.muenchenstein.ch"
TEST_CASES = {
"Abfuhrkreis Ost": {"waste_district": "Abfuhrkreis Ost"},
"Abfuhrkreis West": {"waste_district": "492"},
}
API_URL = "https://www.muenchenstein.ch/abfuhrdaten"
IconMap = {
ICON_MAP = {
"kehricht-und-kleinsperrgut-brennbar": "mdi:trash-can-outline",
"hackseldienst": "mdi:leaf",
"papierabfuhr": "mdi:newspaper-variant-multiple-outline",
@@ -28,7 +30,7 @@ class Source:
self._waste_district = waste_district
def fetch(self):
response = requests.get(URL)
response = requests.get(API_URL)
html = BeautifulSoup(response.text, "html.parser")
@@ -51,26 +53,30 @@ class Source:
Collection(
date=next_pickup_date,
t=waste_type,
icon=IconMap.get(waste_type_sorted, "mdi:trash-can"),
icon=ICON_MAP.get(waste_type_sorted, "mdi:trash-can"),
)
)
# Collection of "Kehricht und Kleinsperrgut brennbar" are not listed with dates as events on website.
# Instead it states the day of the week for each waste district: tuesday for east and friday for west
# So we're going to set those collections programmatically for the next 4 occurrences
weekday_collection = 2 if self._waste_district == 'Abfuhrkreis Ost' or self._waste_district == 491 else 5
weekday_collection = (
2
if self._waste_district == "Abfuhrkreis Ost" or self._waste_district == 491
else 5
)
weekday_today = datetime.now().isoweekday()
for x in range(4):
days_to_pickup = (x * 7) + ((weekday_collection - weekday_today) % 7)
next_pickup_date = (datetime.now() + timedelta(days=days_to_pickup)).date()
waste_type = "Kehricht und Kleinsperrgut brennbar"
waste_type_sorted = waste_type.lower().replace(' ', '-')
waste_type_sorted = waste_type.lower().replace(" ", "-")
entries.append(
Collection(
date=next_pickup_date,
t=waste_type,
icon=IconMap.get(waste_type_sorted, "mdi:trash-can"),
icon=ICON_MAP.get(waste_type_sorted),
)
)

View File

@@ -0,0 +1,39 @@
# Abfallsammlung Münchenstein, BL, Switzerland
Support for schedules provided by [https://www.muenchenstein.ch/abfallsammlung](https://www.muenchenstein.ch/abfallsammlung).
This source is just a slight modification of [@atrox06](https://github.com/atrox06)'s work for lindau_ch. So kudos to him.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: muenchenstein_ch
args:
waste_district: DISTRICT
```
### Configuration Variables
**waste_district**
*(string) (required)*
Valid options for waste_district:
- Abfuhrkreis Ost
- Abfuhrkreis West
or use one the following IDs: 491 for "Ost", 492 for "West"
## Example
```yaml
waste_collection_schedule:
sources:
- name: muenchenstein_ch
args:
waste_district: Abfuhrkreis West
```

View File

@@ -27,7 +27,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Norway | Min Renovasjon, Oslo Kommune |
| Poland | Ecoharmonogram, Warsaw |
| Sweden | Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, 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, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
| 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 |
| United Kingdom | Ashfield District Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, City of York Council, Colchester Borough Council, Cornwall Council, Derby City Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Harlow Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, North Somerset Council, Nottingham City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council |
| United States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |
<!--End of country section-->