Add source for Seattle Public Utilities

This commit is contained in:
Sarah Guermond
2021-02-06 18:32:39 -08:00
parent 6e88d946d5
commit 987c20b680
3 changed files with 92 additions and 0 deletions

View File

@@ -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

View File

@@ -0,0 +1,59 @@
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
self._start_time = int(time.time())
def fetch(self):
# get json file
r = requests.get(
f"https://www.seattle.gov/UTIL/WARP/CollectionCalendar/GetCollectionDays?pApp=CC&pAddress={quote(self._street_address)}&start={self._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
View 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.