mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 05:06:33 +01:00
Merge pull request #30 from sguermond/master
Add source for Seattle Public Utilities
This commit is contained in:
@@ -38,6 +38,7 @@ Currently the following service providers are supported:
|
||||
- [PGH.ST](./doc/source/pgh_st.md)
|
||||
- [Stadtreinigung.Hamburg](./doc/source/stadtreinigung_hamburg.md)
|
||||
- [Abfallwirtschaft Zollernalbkreis](./doc/source/abfall_zollernalbkreis_de.md)
|
||||
- [Seattle Public Utilities](./doc/source/seattle_gov.md)
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import datetime
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
from urllib.parse import quote
|
||||
from ..helpers import CollectionAppointment
|
||||
|
||||
|
||||
DESCRIPTION = "Source for Seattle Public Utilities waste collection."
|
||||
URL = "https://myutilities.seattle.gov/eportal/#/accountlookup/calendar"
|
||||
TEST_CASES = {
|
||||
"City Hall": {"street_address": "600 4th Ave"},
|
||||
"Honey Hole": {"street_address": "703 E Pike St"},
|
||||
"Carmona Court": {"street_address": "1127 17th Ave E"}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, street_address):
|
||||
self._street_address = street_address
|
||||
|
||||
def fetch(self):
|
||||
start_time = int(time.time())
|
||||
|
||||
# get json file
|
||||
r = requests.get(
|
||||
f"https://www.seattle.gov/UTIL/WARP/CollectionCalendar/GetCollectionDays?pApp=CC&pAddress={quote(self._street_address)}&start={start_time}"
|
||||
)
|
||||
|
||||
# extract data from json
|
||||
data = json.loads(r.text)
|
||||
next_pickup = data[0]
|
||||
|
||||
if not next_pickup["start"]:
|
||||
return []
|
||||
|
||||
next_pickup_date = datetime.datetime.strptime(next_pickup["start"], "%a, %d %b %Y").date()
|
||||
|
||||
# create entries for trash, recycling, and yard waste
|
||||
entries = []
|
||||
|
||||
if next_pickup["Garbage"]:
|
||||
entries.append(CollectionAppointment(
|
||||
date=next_pickup_date,
|
||||
t="Trash",
|
||||
icon="mdi:trash-can"))
|
||||
if next_pickup["FoodAndYardWaste"]:
|
||||
entries.append(CollectionAppointment(
|
||||
date=next_pickup_date,
|
||||
t="Food and Yard Waste",
|
||||
icon="mdi:leaf"))
|
||||
if next_pickup["Recycling"]:
|
||||
entries.append(CollectionAppointment(
|
||||
date=next_pickup_date,
|
||||
t="Recycling",
|
||||
icon="mdi:recycle"))
|
||||
|
||||
return entries
|
||||
32
doc/source/seattle_gov.md
Normal file
32
doc/source/seattle_gov.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Seattle Public Utilities
|
||||
|
||||
Support for schedules provided by [Seattle Public Utilities](https://myutilities.seattle.gov/eportal/#/accountlookup/calendar), serving the city of Seattle, WA, USA.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: seattle_gov
|
||||
args:
|
||||
street_address: STREET_ADDRESS
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**street_address**<br>
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: seattle_gov
|
||||
args:
|
||||
street_address: 600 4th Ave
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
The source argument is simply the house mailing address. Road type (eg. St, Ave) and cardinal direction if applicable (eg. N/S/NW) are required, so "501 23rd Ave" and "501 23rd Ave E" will give different results.
|
||||
Reference in New Issue
Block a user