mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
add snaga_mb_si
This commit is contained in:
@@ -1479,6 +1479,7 @@ If your service provider is not listed, feel free to open a [source request issu
|
||||
<summary>Slovenia</summary>
|
||||
|
||||
- [Moji odpadki, Ljubljana](/doc/source/mojiodpadki_si.md) / mojiodpadki.si
|
||||
- [Snaga Maribor](/doc/source/snaga_mb_si.md) / snaga-mb.si
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
@@ -9516,6 +9516,12 @@
|
||||
"module": "mojiodpadki_si",
|
||||
"default_params": {},
|
||||
"id": "mojiodpadki_si"
|
||||
},
|
||||
{
|
||||
"title": "Snaga Maribor",
|
||||
"module": "snaga_mb_si",
|
||||
"default_params": {},
|
||||
"id": "snaga_mb_si"
|
||||
}
|
||||
],
|
||||
"Sweden": [
|
||||
|
||||
@@ -15637,6 +15637,28 @@
|
||||
"subarea": "Subarea"
|
||||
},
|
||||
"data_description": {}
|
||||
},
|
||||
"args_snaga_mb_si": {
|
||||
"title": "Quelle konfigurieren",
|
||||
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md",
|
||||
"data": {
|
||||
"calendar_title": "Kalender Titel",
|
||||
"house_number": "Hausnummer",
|
||||
"street": "Straße"
|
||||
},
|
||||
"data_description": {
|
||||
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
|
||||
}
|
||||
},
|
||||
"reconfigure_snaga_mb_si": {
|
||||
"title": "Quelle Neu Konfigurieren",
|
||||
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md",
|
||||
"data": {
|
||||
"calendar_title": "Kalender Titel",
|
||||
"house_number": "Hausnummer",
|
||||
"street": "Straße"
|
||||
},
|
||||
"data_description": {}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
|
||||
@@ -15637,6 +15637,28 @@
|
||||
"subarea": "Subarea"
|
||||
},
|
||||
"data_description": {}
|
||||
},
|
||||
"args_snaga_mb_si": {
|
||||
"title": "Configure Source",
|
||||
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md.",
|
||||
"data": {
|
||||
"calendar_title": "Calendar Title",
|
||||
"house_number": "House Number",
|
||||
"street": "Street"
|
||||
},
|
||||
"data_description": {
|
||||
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used."
|
||||
}
|
||||
},
|
||||
"reconfigure_snaga_mb_si": {
|
||||
"title": "Reconfigure Source",
|
||||
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md.",
|
||||
"data": {
|
||||
"calendar_title": "Calendar Title",
|
||||
"house_number": "House Number",
|
||||
"street": "Street"
|
||||
},
|
||||
"data_description": {}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
|
||||
@@ -15612,6 +15612,28 @@
|
||||
"subarea": "Subarea"
|
||||
},
|
||||
"data_description": {}
|
||||
},
|
||||
"args_snaga_mb_si": {
|
||||
"title": "Configurazione Sorgente",
|
||||
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md.",
|
||||
"data": {
|
||||
"calendar_title": "Nome Calendario",
|
||||
"house_number": "Civico",
|
||||
"street": "Strada"
|
||||
},
|
||||
"data_description": {
|
||||
"calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi."
|
||||
}
|
||||
},
|
||||
"reconfigure_snaga_mb_si": {
|
||||
"title": "Riconfigurazione Sorgente",
|
||||
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md.",
|
||||
"data": {
|
||||
"calendar_title": "Nome Calendario",
|
||||
"house_number": "Civico",
|
||||
"street": "Strada"
|
||||
},
|
||||
"data_description": {}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "Snaga Maribor"
|
||||
DESCRIPTION = "Source for Snaga Maribor."
|
||||
URL = "https://snaga-mb.si/"
|
||||
TEST_CASES = {
|
||||
"Ruska ulica 24": {"street": "Ruska ulica", "house_number": 24},
|
||||
}
|
||||
|
||||
|
||||
BIN_TYPES = {
|
||||
"O": "Ost.",
|
||||
"B": "Bio.",
|
||||
"U": "Emb.",
|
||||
"P": "Pap.",
|
||||
"S": "Stek.",
|
||||
}
|
||||
ICON_MAP = {
|
||||
"O": "mdi:trash-can",
|
||||
"B": "mdi:leaf",
|
||||
"U": "mdi:recycle",
|
||||
"P": "mdi:newspaper",
|
||||
"S": "mdi:glass-cocktail",
|
||||
}
|
||||
|
||||
BASE_URL = "https://arhiv.snaga-mb.si/mso"
|
||||
ADDRESS_ID_URL = f"{BASE_URL}/tmRSkjpgG.php"
|
||||
COLLECTION_URL = f"{BASE_URL}/tmRSk.php"
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, street: str, house_number: str | int):
|
||||
self._street: str = street
|
||||
self._house_number: str | int = house_number
|
||||
|
||||
def fetch(self) -> list[Collection]:
|
||||
args = {
|
||||
"Naziv": self._street,
|
||||
"HS": self._house_number,
|
||||
"IDo": "0",
|
||||
"_": int(datetime.now().timestamp() * 1000),
|
||||
}
|
||||
r = requests.get(ADDRESS_ID_URL, params=args)
|
||||
r.raise_for_status()
|
||||
if r.text == "null" or not r.json():
|
||||
raise Exception("Invalid address")
|
||||
|
||||
entries = []
|
||||
for id in r.json():
|
||||
address_id = id["OM"]
|
||||
r = requests.get(
|
||||
COLLECTION_URL,
|
||||
params={"sql": address_id, "_": int(datetime.now().timestamp() * 1000)},
|
||||
)
|
||||
|
||||
for collection in r.json():
|
||||
day = int(collection["Dan"])
|
||||
month = int(collection["Mesec"])
|
||||
year = int(collection["Leto"])
|
||||
date_ = date(year, month, day)
|
||||
type_char = collection["Odp"]
|
||||
bin_type = BIN_TYPES.get(type_char, type_char)
|
||||
icon = ICON_MAP.get(type_char)
|
||||
entries.append(Collection(date=date_, t=bin_type, icon=icon))
|
||||
|
||||
return entries
|
||||
39
doc/source/snaga_mb_si.md
Normal file
39
doc/source/snaga_mb_si.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Snaga Maribor
|
||||
|
||||
Support for schedules provided by [Snaga Maribor](https://snaga-mb.si/), serving Snaga Maribor, Slovenia.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: snaga_mb_si
|
||||
args:
|
||||
street: STREET (Naziv)
|
||||
house_number: "HOUSE NUMBER (HS)"
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**street**
|
||||
*(String) (required)*
|
||||
**house_number**
|
||||
*(String | Integer) (required)*
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: snaga_mb_si
|
||||
args:
|
||||
street: Ruska ulica
|
||||
house_number: "24"
|
||||
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
Find the parameter of your address using [https://snaga-mb.si/koledar-odvoza-odpadkov/](https://snaga-mb.si/koledar-odvoza-odpadkov/) and write them exactly like on the web page.
|
||||
Reference in New Issue
Block a user