mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
Added source for uppsalavatten_se and updated readme.md+info.md
This commit is contained in:
@@ -0,0 +1,85 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
import urllib.parse
|
||||||
|
import json
|
||||||
|
import requests
|
||||||
|
from waste_collection_schedule import Collection
|
||||||
|
|
||||||
|
TITLE = "Uppsala Vatten och Avfall AB"
|
||||||
|
DESCRIPTION = "Source script for uppsalavatten.se"
|
||||||
|
URL = "https://www.uppsalavatten.se"
|
||||||
|
|
||||||
|
TEST_CASES = {
|
||||||
|
"Test1": {"city": "BJÖRKLINGE", "street": "SADELVÄGEN 1",},
|
||||||
|
"Test2": {"city": "BJÖRKLINGE", "street": "BJÖRKLINGE-GRÄNBY 33",},
|
||||||
|
"Test3": {"city": "BJÖRKLINGE", "street": "BJÖRKLINGE-GRÄNBY 20",},
|
||||||
|
}
|
||||||
|
|
||||||
|
API_URLS = {
|
||||||
|
"address_search": "https://futureweb.uppsalavatten.se/Uppsala/FutureWebBasic/SimpleWastePickup/SearchAdress",
|
||||||
|
"collection": "https://futureweb.uppsalavatten.se/Uppsala/FutureWebBasic/SimpleWastePickup/GetWastePickupSchedule",
|
||||||
|
}
|
||||||
|
|
||||||
|
ICON_MAP = {
|
||||||
|
"Restavfall": "mdi:trash-can",
|
||||||
|
"Matavfall": "mdi:food-apple",
|
||||||
|
"Slam": "",
|
||||||
|
}
|
||||||
|
|
||||||
|
MONTH_MAP = {
|
||||||
|
"Jan": 1,
|
||||||
|
"Feb": 2,
|
||||||
|
"Mar": 3,
|
||||||
|
"Apr": 4,
|
||||||
|
"Maj": 5,
|
||||||
|
"Jun": 6,
|
||||||
|
"Jul": 7,
|
||||||
|
"Aug": 8,
|
||||||
|
"Sep": 9,
|
||||||
|
"Okt": 10,
|
||||||
|
"Nov": 11,
|
||||||
|
"Dec": 12,
|
||||||
|
}
|
||||||
|
|
||||||
|
class Source:
|
||||||
|
def __init__(self, street, city):
|
||||||
|
self.street = street
|
||||||
|
self.city = city
|
||||||
|
#self.facid = facid
|
||||||
|
|
||||||
|
def fetch(self):
|
||||||
|
#request to get facility id
|
||||||
|
addresslist = requests.post(
|
||||||
|
API_URLS["address_search"], {"searchText": f"{self.street.upper()}, {self.city.upper()}"}
|
||||||
|
)
|
||||||
|
addresslist.raise_for_status()
|
||||||
|
adresslist_json = json.loads(addresslist.text)
|
||||||
|
|
||||||
|
payload = {"address": adresslist_json['Buildings'][0]}
|
||||||
|
|
||||||
|
payload_str = urllib.parse.urlencode(payload, encoding="utf8")
|
||||||
|
# request for the wasteschedule
|
||||||
|
wasteschedule = requests.get(API_URLS["collection"], params=payload_str)
|
||||||
|
wasteschedule.raise_for_status()
|
||||||
|
|
||||||
|
data = json.loads(wasteschedule.text)
|
||||||
|
entries = []
|
||||||
|
for i in data['RhServices']:
|
||||||
|
icon=ICON_MAP.get(i["WasteType"])
|
||||||
|
if "v" in i["NextWastePickup"]:
|
||||||
|
date_parts = i["NextWastePickup"].split()
|
||||||
|
month = MONTH_MAP[date_parts[1]]
|
||||||
|
date_joined = "-".join([date_parts[0], str(month), date_parts[2]])
|
||||||
|
date = datetime.strptime(date_joined, "v%W-%m-%Y").date()
|
||||||
|
elif not i["NextWastePickup"]:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
date=datetime.strptime(i["NextWastePickup"], "%Y-%m-%d").date()
|
||||||
|
|
||||||
|
entries.append(
|
||||||
|
Collection(
|
||||||
|
t=i["WasteType"],
|
||||||
|
icon=icon,
|
||||||
|
date=date,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return entries
|
||||||
42
doc/source/uppsalavatten_se.md
Normal file
42
doc/source/uppsalavatten_se.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Uppsala Vatten och Avfall AB
|
||||||
|
|
||||||
|
Support for schedules provided by [Uppsala Vatten och Avfall AB](https://www.uppsalavatten.se), serving the municipality of Uppsala.
|
||||||
|
|
||||||
|
## Configuration via configuration.yaml
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
waste_collection_schedule:
|
||||||
|
sources:
|
||||||
|
- name: uppsalavatten_se
|
||||||
|
args:
|
||||||
|
street: STREET_NAME
|
||||||
|
city: CITY_NAME
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration Variables
|
||||||
|
|
||||||
|
**street**
|
||||||
|
*(string) (required)*
|
||||||
|
|
||||||
|
**city**
|
||||||
|
*(string) (required)*
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
waste_collection_schedule:
|
||||||
|
sources:
|
||||||
|
- name: uppsalavatten_se
|
||||||
|
args:
|
||||||
|
street: SADELVÄGEN 1
|
||||||
|
city: BJÖRKLINGE
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## How to get the source argument
|
||||||
|
|
||||||
|
The source argument is the street including number and the city to the house with waste collection.
|
||||||
|
The address can be tested [here](https://www.uppsalavatten.se/sjalvservice/hamtningar-och-berakningar/dag-for-sophamtning-och-slamtomning).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user