From 987c20b680273f64478725bc173ea87e103f7748 Mon Sep 17 00:00:00 2001 From: Sarah Guermond Date: Sat, 6 Feb 2021 18:32:39 -0800 Subject: [PATCH 1/2] Add source for Seattle Public Utilities --- README.md | 1 + .../package/source/seattle_gov.py | 59 +++++++++++++++++++ doc/source/seattle_gov.md | 32 ++++++++++ 3 files changed, 92 insertions(+) create mode 100644 custom_components/waste_collection_schedule/package/source/seattle_gov.py create mode 100644 doc/source/seattle_gov.md 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..4b284b84 --- /dev/null +++ b/custom_components/waste_collection_schedule/package/source/seattle_gov.py @@ -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 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 From df5069895b74c66b9049e0486912a92fec60a2ef Mon Sep 17 00:00:00 2001 From: Sarah Guermond Date: Sat, 13 Feb 2021 17:52:51 -0800 Subject: [PATCH 2/2] Move start_time to fetch method instead of init --- .../waste_collection_schedule/package/source/seattle_gov.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/custom_components/waste_collection_schedule/package/source/seattle_gov.py b/custom_components/waste_collection_schedule/package/source/seattle_gov.py index 4b284b84..4f7b80f8 100644 --- a/custom_components/waste_collection_schedule/package/source/seattle_gov.py +++ b/custom_components/waste_collection_schedule/package/source/seattle_gov.py @@ -20,12 +20,13 @@ TEST_CASES = { class Source: def __init__(self, street_address): self._street_address = street_address - self._start_time = int(time.time()) 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={self._start_time}" + f"https://www.seattle.gov/UTIL/WARP/CollectionCalendar/GetCollectionDays?pApp=CC&pAddress={quote(self._street_address)}&start={start_time}" ) # extract data from json