-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support fo "Renhållningen Kristianstad" in Kristianstad, Sweden (#…
…2741) * Initial commit adding support for Kristianstad Renhållning Sweden * Initial commit adding documentation for Kristianstad Renhållning Sweden * Updated readme.md with Renhållningen Kristianstad (Sweden) * Fix error with urlencode * Fixed "Lints" * Major fix due to diff in running code and repo * Changing returning empty result on unknown street address to raising exception * Rename from krab_se to renhallningen_kristianstad_se * reformatting * ./update_docu_links.py --------- Co-authored-by: Hans Bäcklund <[email protected]> Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
1 parent
6451791
commit 22874af
Showing
8 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ste_collection_schedule/waste_collection_schedule/source/renhallningen_kristianstad_se.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters