diff --git a/README.md b/README.md index 9f2e62d0..d49c4c21 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/custom_components/waste_collection_schedule/package/source/seattle_gov.py b/custom_components/waste_collection_schedule/package/source/seattle_gov.py new file mode 100644 index 00000000..4f7b80f8 --- /dev/null +++ b/custom_components/waste_collection_schedule/package/source/seattle_gov.py @@ -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 diff --git a/doc/source/seattle_gov.md b/doc/source/seattle_gov.md new file mode 100644 index 00000000..1eb3e677 --- /dev/null +++ b/doc/source/seattle_gov.md @@ -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**
+*(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. \ No newline at end of file