Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support fo "Renhållningen Kristianstad" in Kristianstad, Sweden #2741

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Gästrike Återvinnare](/doc/source/gastrikeatervinnare_se.md) / gastrikeatervinnare.se
- [Jönköping - June Avfall & Miljö](/doc/source/juneavfall_se.md) / juneavfall.se
- [Kretslopp Sydost](/doc/source/edpevent_se.md) / kretsloppsydost.se
- [Renhållningen Kristianstad](/doc/source/krab_se.md) / renhallningen-kristianstad.se/
- [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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import json
import urllib
from datetime import datetime

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Kristianstad Renhållning"
DESCRIPTION = "Source for Kristianstad Renhållning waste collection."
URL = "https://renhallningen-kristianstad.se"
TEST_CASES = {
"Case_0": {"street_address": "Östra Boulevarden 1"},
"Case_1": {"street_address": "Grenadjärvägen 1"},
"Case_2": {"street_address": "Skogsvägen 18"},
"Case_3": {"street_address": "Önnestadsvägen 7"},
}


class Source:
def __init__(self, street_address):
self._street_address = street_address

def fetch(self):
headers = {"Module": "universal",
"Accept": "application/json, text/plain, */*",
"Unit": "dd905ce7-b16d-4422-be36-564169af4035"}
query_street_address = urllib.parse.quote(self._street_address)
response = requests.get(
f"https://api-universal.appbolaget.se/waste/addresses/search?query={query_street_address}",
headers=headers,
)

building_data = json.loads(response.text)["data"]
building_id = None
if building_data and len(building_data) > 0:
building_id = building_data[0]["uuid"]

if not building_id:
raise ValueError('Unknown street address')

headers = {"Module": "universal",
"Accept": "application/json, text/plain, */*",
"Unit": "dd905ce7-b16d-4422-be36-564169af4035"}
response = requests.get(
f"https://api-universal.appbolaget.se/waste/addresses/{building_id}",
headers=headers,
)

data = json.loads(response.text)["data"]["services"]

entries = []
for item in data:
waste_type = item["type"]
icon = "mdi:trash-can"
if waste_type == "Trädgårdsavfall":
icon = "mdi:leaf"
next_pickup = item["collection_at"]
next_pickup_date = datetime.fromisoformat(next_pickup).date()
entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon))

return entries
32 changes: 32 additions & 0 deletions doc/source/renhallningen_kristianstad_se.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kristianstad Renhållning Sophämntning

Support for schedules provided by [Kristianstad Renhållning](https://renhallningen-kristianstad.se/villa-fritidshus/tomning-av-sopkarl/tomningschema/), serving the municipality of Kristianstad Sweden.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: renhallningen_kristianstad_se
args:
street_address: STREET_ADDRESS
```

### Configuration Variables

**street_address**
*(string) (required)*

## Example

```yaml
waste_collection_schedule:
sources:
- name: renhallningen_kristianstad_se
args:
street_address: Östra Boulevarden 1
```

## 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://renhallningen-kristianstad.se/villa-fritidshus/tomning-av-sopkarl/tomningschema/).