add lumire_se

This commit is contained in:
5ila5
2024-08-12 15:19:37 +02:00
committed by 5ila5
parent 871946541d
commit e0e5580a61
5 changed files with 106 additions and 1 deletions

View File

@@ -1294,6 +1294,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Landskrona - Svalövs Renhållning](/doc/source/lsr_nu.md) / lsr.nu
- [Lerum Vatten och Avlopp](/doc/source/lerum_se.md) / vatjanst.lerum.se
- [Linköping - Tekniska Verken](/doc/source/tekniskaverken_se.md) / tekniskaverken.se
- [Luleå](/doc/source/lumire_se.md) / lumire.se
- [Lund Waste Collection](/doc/source/lund_se.md) / eservice431601.lund.se
- [Mölndal](/doc/source/molndal_se.md) / molndal.se
- [Norrtalje Vatten & Avfall](/doc/source/nvaa_se.md) / sjalvservice.nvaa.se

View File

@@ -6998,6 +6998,11 @@
"module": "tekniskaverken_se",
"default_params": {}
},
{
"title": "Lule\u00e5",
"module": "lumire_se",
"default_params": {}
},
{
"title": "Lund Waste Collection",
"module": "lund_se",

View File

@@ -0,0 +1,65 @@
from datetime import datetime
import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Luleå"
DESCRIPTION = "Source for Luleå."
URL = "https://www.lumire.se/"
TEST_CASES = {
"Storgatan 2": {"address": "Storgatan 2"},
"Ringgatan 20": {"address": "Ringgatan 20"},
}
ICON_MAP = {
"Restavfall": "mdi:trash-can",
"Matavfall": "mdi:leaf",
"Porslin": "mdi:coffee",
"Returpapper": "mdi:package-variant",
"Pappersförpackningar": "mdi:package-variant",
"Plastförpackningar": "mdi:recycle",
"Metallförpackningar": "mdi:recycle",
"Färgade": "mdi:bottle-soda",
"Ofärgade": "mdi:bottle-soda",
"Ljuskällor": "mdi:lightbulb",
"Småbatterier": "mdi:battery",
}
API_URL = "https://www.lumire.se/wp-admin/admin-ajax.php"
HEADERS = {"User-Agent": "Mozilla/5.0"}
class Source:
def __init__(self, address: str):
self._address: str = address
def fetch(self) -> list[Collection]:
data = {"search_address": self._address, "action": "waste_pickup_form"}
r = requests.post(API_URL, data=data, headers=HEADERS)
r.raise_for_status()
if "Den adress du har angivit finns inte i v\u00e5rt system" in r.text:
raise ValueError("Address not found")
data_list = (
r.text.encode()
.decode("unicode_escape")
.replace(r"\/", "/")
.strip('"')
.split("<br>")
)
collections = zip(data_list[::2], data_list[1::2])
entries = []
for bin_type, date_str in collections:
date_str = date_str.replace(":", "").strip()
date_ = datetime.strptime(date_str, "%Y-%m-%d").date()
bin_type = bin_type.replace("Nästa tömning för", "").strip()
icon = ICON_MAP.get(bin_type.split()[0])
entries.append(Collection(date_, bin_type, icon))
return entries

34
doc/source/lumire_se.md Normal file
View File

@@ -0,0 +1,34 @@
# Luleå
Support for schedules provided by [Luleå](https://www.lumire.se/), serving Luleå, Sweden.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: lumire_se
args:
address: ADDRESS
```
### Configuration Variables
**address**
*(String) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: lumire_se
args:
address: Storgatan 2
```
## How to get the source argument
You can test your address parameter at [https://www.lumire.se/#anch-sokmodul](https://www.lumire.se/#anch-sokmodul).

File diff suppressed because one or more lines are too long