mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
Add source for Republic Services (USA)
Adding source for a relatively large (I think) USA municipal waste service. This should work for Commercial, Residential, and Industrial service. Feel free to correct mistakes, propose fixes, improvements, best practices, etc. I'm a novice, so happy to fix my poor code :-). Cheers! DeadEnd
This commit is contained in:
@@ -140,6 +140,7 @@ Currently the following service providers are supported:
|
||||
### United States of America
|
||||
|
||||
- [PGH.ST](./doc/source/pgh_st.md)
|
||||
- [Republic Services](.doc/source/republicservices_com.md)
|
||||
- [Seattle Public Utilities](./doc/source/seattle_gov.md)
|
||||
|
||||
### United Kingdom
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from datetime import datetime
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "Republic Services"
|
||||
DESCRIPTION = "Source for Republic Services Collection."
|
||||
URL = "https://www.republicservices.com"
|
||||
TEST_CASES = {
|
||||
"Scott Country Clerk": {"street_address": "101 E Main St, Georgetown, KY 40324"},
|
||||
"Branch County Clerk": {"street_address": "31 Division St. Coldwater, MI 49036"}
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, street_address):
|
||||
self._street_address = street_address
|
||||
|
||||
def fetch(self):
|
||||
response1 = requests.get(
|
||||
"https://www.republicservices.com/api/v1/addresses",
|
||||
params={"addressLine1": self._street_address},
|
||||
)
|
||||
|
||||
address_hash = json.loads(response1.text)["data"][0]["addressHash"]
|
||||
|
||||
response2 = requests.get(
|
||||
"https://www.republicservices.com/api/v1/publicPickup",
|
||||
params={"siteAddressHash": address_hash},
|
||||
)
|
||||
|
||||
r_json = json.loads(response2.text)["data"]
|
||||
|
||||
entries = []
|
||||
|
||||
for x in r_json:
|
||||
if hasattr(r_json[x], "__iter__"):
|
||||
for item in r_json[x]:
|
||||
waste_type = item["wasteTypeDescription"]
|
||||
icon = "mdi:trash-can"
|
||||
if waste_type == "Recycle":
|
||||
icon = "mdi:recycle"
|
||||
for day in item["nextServiceDays"]:
|
||||
next_pickup = day
|
||||
next_pickup_date = datetime.fromisoformat(next_pickup).date()
|
||||
entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon))
|
||||
|
||||
return entries
|
||||
32
doc/source/republicservices_com.md
Normal file
32
doc/source/republicservices_com.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Republic Services
|
||||
|
||||
Support for schedules provided by [Republic Services](https://republicservices.com), serving the municipality all over the United States of America.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: republicservices_com
|
||||
args:
|
||||
street_address: STREET_ADDRESS
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**street_address**<br>
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: republicservices_com
|
||||
args:
|
||||
street_address: "101 E Main St, Georgetown, KY 40324"
|
||||
```
|
||||
|
||||
## How to check the street address
|
||||
|
||||
The street address can be tested [here](https://republicservices.com).
|
||||
1
info.md
1
info.md
@@ -126,6 +126,7 @@ Currently the following service providers are supported:
|
||||
### United States of America
|
||||
|
||||
- [PGH.ST](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pgh_st.md)
|
||||
- [Republic Services](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/republicservices_com.md)
|
||||
- [Seattle Public Utilities](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/seattle_gov.md)
|
||||
|
||||
### United Kingdom
|
||||
|
||||
Reference in New Issue
Block a user