Add Odense Renovation source (#2415)

* Add Odense Renovation source

* reformatting

---------

Co-authored-by: Frederik Rosenberg <frederik@schultz-rosenberg.dk>
Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
Frederik Rosenberg
2024-08-10 14:23:56 +02:00
committed by GitHub
parent b8bf8455d6
commit 88cc97e886
6 changed files with 111 additions and 3 deletions

View File

@@ -551,6 +551,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Langeland Forsyning](/doc/source/affaldonline_dk.md) / langeland-forsyning.dk
- [Middelfart Kommune](/doc/source/affaldonline_dk.md) / middelfart.dk
- [Nyborg Forsyning & Service A/S](/doc/source/affaldonline_dk.md) / nfs.as
- [Odense Renovation](/doc/source/odenserenovation_dk.md) / odenserenovation.dk
- [Rebild Kommune](/doc/source/affaldonline_dk.md) / rebild.dk
- [Reno Djurs](/doc/source/renodjurs_dk.md) / renodjurs.dk
- [Renosyd](/doc/source/renosyd_dk.md) / renosyd.dk

View File

@@ -2579,6 +2579,11 @@
"municipality": "nyborg"
}
},
{
"title": "Odense Renovation",
"module": "odenserenovation_dk",
"default_params": {}
},
{
"title": "Rebild Kommune",
"module": "affaldonline_dk",

View File

@@ -280,7 +280,8 @@
"abfall": "Abfall",
"english": "English",
"voivodeship": "Voivodeship",
"building_id": "Building Id"
"building_id": "Building Id",
"addressNo": "Address No"
},
"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."
@@ -532,7 +533,8 @@
"abfall": "Abfall",
"english": "English",
"voivodeship": "Voivodeship",
"building_id": "Building Id"
"building_id": "Building Id",
"addressNo": "Address No"
}
}
},

View File

@@ -0,0 +1,62 @@
from datetime import datetime, timedelta
import requests
from waste_collection_schedule import Collection
TITLE = "Odense Renovation"
DESCRIPTION = "Source for Odense Renovation"
URL = "https://odenserenovation.dk"
TEST_CASES = {
"Jernbanegade 19, Odense C": {"addressNo": 122518},
"Nyborgvej 3, Odense C": {"addressNo": 133517},
"Næsbyhave 105, Odense N": {"addressNo": 134008},
}
API_URL = "https://mit.odenserenovation.dk/api/Calendar/GetCalendarByAddress"
ICON_MAP = {
"00": "mdi:trash-can", # Mad- og restaffald
"10": "mdi:archive", # Glas & metal og papir & småt pap
"20": "mdi:trash-can", # Restaffald
"30": "mdi:food-apple", # Madaffald
"40": "mdi:archive", # Papir & småt pap
"50": "mdi:bottle-wine", # Glas & Metal
"60": "mdi:bottle-soda", # Plast og mad- & drikkekartoner
}
class Source:
def __init__(self, addressNo: int):
self.addressNo = addressNo
def fetch(self):
fromDate = datetime.now()
toDate = datetime.now() + timedelta(days=+365)
response = requests.get(
API_URL,
params={
"addressNo": self.addressNo,
"startDate": fromDate.isoformat(),
"endDate": toDate.isoformat(),
"noCache": False,
},
)
response.raise_for_status()
months = response.json()["Months"]
entries = []
for month in months:
for day in month["Days"]:
date = datetime.strptime(day["Date"], "%Y-%m-%dT%H:%M:%S").date()
for bin in day["Bins"]:
entries.append(
Collection(
date=date,
t=bin["Label"],
icon=ICON_MAP.get(bin["BinCode"], "mdi:trash-can-outline"),
)
)
return entries

View File

@@ -0,0 +1,38 @@
# Odense Renovation
Support for schedules provided by [Odense Renovation](https://odenserenovation.dk/), serving Odense, Denmark.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: odenserenovation_dk
args:
addressNo: Address number
```
### Configuration Variables
**addressNo**
_(int) (required)_
## Example
```yaml
waste_collection_schedule:
sources:
- name: odenserenovation_dk
args:
addressNo: 133517
```
## How to get the addressNo
Go to the [Se tømningskalender](https://mit.odenserenovation.dk/hentkalender) page, enter your address.
In the URL (web page address) copy the number after `addressNo=`
`I.e.` [`https://mit.odenserenovation.dk/downloadkalender?addressNo=133517`](https://mit.odenserenovation.dk/downloadkalender?addressNo=133517)
Then it's the `133517` part used in the integration

File diff suppressed because one or more lines are too long