Add support for Vestforbrænding in Denmark (#2231)

* Add support for Vestforbrænding in Denmark

* Fix request

* Add context to logging

* reformatting

* fix merge error

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
Co-authored-by: 5ila5 <38183212+5ila5@users.noreply.github.com>
This commit is contained in:
Michael Bendtsen
2024-07-11 20:06:46 +02:00
committed by GitHub
parent 16ed4e4bed
commit 17cc1e020b
6 changed files with 134 additions and 3 deletions

View File

@@ -549,6 +549,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Silkeborg Forsyning](/doc/source/affaldonline_dk.md) / silkeborgforsyning.dk
- [Sorø Kommune](/doc/source/affaldonline_dk.md) / soroe.dk
- [Vejle Kommune](/doc/source/affaldonline_dk.md) / vejle.dk
- [Vestforbrænding](/doc/source/vestfor_dk.md) / selvbetjening.vestfor.dk
- [Ærø Kommune](/doc/source/affaldonline_dk.md) / aeroekommune.dk
</details>

View File

@@ -1901,6 +1901,11 @@
"municipality": "vejle"
}
},
{
"title": "Vestforbr\u00e6nding",
"module": "vestfor_dk",
"default_params": {}
},
{
"title": "\u00c6r\u00f8 Kommune",
"module": "affaldonline_dk",

View File

@@ -259,7 +259,10 @@
"bill_number": "Bill Number",
"values": "Values",
"property_no": "Property No",
"postCode": "Post Code"
"postCode": "Post Code",
"zipCode": "Zip Code",
"garden_cutomer": "Garden Cutomer",
"app": "App"
},
"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."
@@ -502,7 +505,10 @@
"bill_number": "Bill Number",
"values": "Values",
"property_no": "Property No",
"postCode": "Post Code"
"postCode": "Post Code",
"zipCode": "Zip Code",
"garden_cutomer": "Garden Cutomer",
"app": "App"
}
}
},

View File

@@ -0,0 +1,76 @@
import datetime
import json
import logging
import requests as request
from waste_collection_schedule import Collection
_LOGGER = logging.getLogger(__name__)
TITLE = "Vestforbrænding" # Title will show up in README.md and info.md
DESCRIPTION = "Source for Vestforbrændning collection" # Describe your source
URL = "https://selvbetjening.vestfor.dk/" # Insert url to service homepage. URL will show up in README.md and info.md
TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py script
"Home": {"streetName": "Kløvertoften", "number": "61", "zipCode": "2740"}
}
API_URL = "https://selvbetjening.vestfor.dk/Adresse/ToemmeDates"
ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons
"Haveaffald": "mdi:leaf",
"Storskrald": "mdi:recycle",
"Mad/Rest affald": "mdi:food",
"Pap": "mdi:archive",
"Papir/Plast \u0026 MDK": "mdi:bottle-soda",
"Metal/Glas affald": "mdi:wrench",
"Juletræer": "mdi:pine-tree",
}
ADRESS_LOOKUP_URL = "https://selvbetjening.vestfor.dk/Adresse/AddressByName"
class Source:
def __init__(self, streetName, number, zipCode):
self._streetName = streetName
self._number = number
self._zipCode = zipCode
def fetch(self):
entries = [] # List that holds collection schedule
term = self._streetName + " " + self._number + ", " + self._zipCode
_LOGGER.info("Fetching addressId from Vestforbrændning: " + term)
addressResponse = request.get(
ADRESS_LOOKUP_URL, params={"term": term, "numberOfResults": 1}
)
addresses = json.loads(addressResponse.text)
if len(addresses) == 0:
raise Exception("No address found for " + term)
addressId = addresses[0]["Id"]
_LOGGER.info("Fetching data from Vestforbrændning")
start_date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S%z")
end_date = (datetime.datetime.now() + datetime.timedelta(days=90)).strftime(
"%Y-%m-%dT%H:%M:%S%z"
)
cookies = {"addressId": addressId}
response = request.get(
API_URL, params={"start": start_date, "end": end_date}, cookies=cookies
)
data = json.loads(response.text)
for item in data:
entries.append(
Collection(
date=datetime.datetime.strptime(
item["start"], "%Y-%m-%d"
).date(), # Collection date
t=item["title"], # Collection type
icon=ICON_MAP.get(item["title"]), # Collection icon
)
)
return entries

43
doc/source/vestfor_dk.md Normal file
View File

@@ -0,0 +1,43 @@
# Vestforbrændning
Support for schedules provided by [Vestforbrændning](https://selvbetjening.vestfor.dk/), serving the municipality of Albertslund, Ballerup, Furesø, Ishøj, and Vallensbæks, Denmark.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: vestfor_dk
args:
streetName: street name
number: house number
zipCode: zip code
```
### Configuration Variables
**streetName**
*(string) (required)*
**number**
*(string) (required)*
**zipCode**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: vestfor_dk
args:
streetName: Kløvertoften
number: 61
zipCode: 2740
```
## How to get the source argument
The source argument is the address to the house with waste collection. The address can be tested [here](https://selvbetjening.vestfor.dk/Adresse/Toemmekalender).

File diff suppressed because one or more lines are too long