Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Republic Services #1348

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import requests
import json

from datetime import datetime, timedelta

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Republic Services"
DESCRIPTION = "Source for Republic Services Collection."
URL = "https://www.republicservices.com"
COUNTRY = "us"
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"},
"Contract Collection": {"street_address": "8957 Park Meadows Dr, Elk Grove, CA 95624"},
"Residential Collection": {"street_address": "117 Roxie Ln, Georgetown, KY 40324"},

"Scott Country Clerk": {
"street_address": "101 E Main St, Georgetown, KY 40324",
"method": 1,
},
"Branch County Clerk": {
"street_address": "31 Division St. Coldwater, MI 49036",
"method": "1",
},
"Contract Collection": {
"street_address": "8957 Park Meadows Dr, Elk Grove, CA 95624",
"method": 2,
},
"Residential Collection": {
"street_address": "117 Roxie Ln, Georgetown, KY 40324",
"method": "2",
},
"No Method arg": {
"street_address": "8957 Park Meadows Dr, Elk Grove, CA 95624",
},
}
DELAYS = {
" one ": 1,
Expand All @@ -27,8 +41,9 @@


class Source:
def __init__(self, street_address):
def __init__(self, street_address, method=1):
self._street_address = street_address
self._method = int(method)

def fetch(self):
s = requests.Session()
Expand Down Expand Up @@ -59,35 +74,42 @@ def fetch(self):
dt = datetime.strptime(day, "%Y-%m-%d").date()
service = item["containerCategory"]
schedule.update(
{i: {
"date": dt,
"waste_type": item["wasteTypeDescription"],
"waste_description": item["productDescription"],
"service": service,
{
i: {
"date": dt,
"waste_type": item["wasteTypeDescription"],
"waste_description": item["productDescription"],
"service": service,
}
}
)
i += 1

# Compile holidays that impact collections
r2 = s.get(f"https://www.republicservices.com/api/v3/holidaySchedules/schedules", params={"latitude": latitude, "longitude": longitude})
r2 = s.get(
"https://www.republicservices.com/api/v3/holidaySchedules/schedules",
params={"latitude": latitude, "longitude": longitude},
)
r2_json = json.loads(r2.text)["data"]
day_offset = 0
i = 0
holidays = {}
for item in r2_json:
if item["serviceImpacted"] == True and item["LOB"] == service:
if item["serviceImpacted"] is True and item["LOB"] == service:
for delay in DELAYS:
if delay in item["description"]:
day_offset = DELAYS[delay]
dt = datetime.strptime(item["date"], "%Y-%m-%dT00:00:00.0000000Z").date()
dt = datetime.strptime(
item["date"], "%Y-%m-%dT00:00:00.0000000Z"
).date()
holidays.update(
{i: {
"date": dt,
"name": item["name"],
"description": item["description"],
"delay": day_offset,
"incorporated": False
{
i: {
"date": dt,
"name": item["name"],
"description": item["description"],
"delay": day_offset,
"incorporated": False,
}
}
)
Expand All @@ -104,7 +126,7 @@ def fetch(self):
p = schedule[pickup]["date"]
date_difference = (p - h).days
if date_difference <= 5 and date_difference >= 0:
revised_date = p + timedelta(days = d)
revised_date = p + timedelta(days=d)
schedule[pickup]["date"] = revised_date
holidays[holiday]["incorporated"] = True
# print(p, h, d, date_difference, revised_date)
Expand All @@ -114,19 +136,40 @@ def fetch(self):

# Build final schedule (implements original logic for assigning icon)
entries = []
for item in schedule:
if "RECYCLE" in schedule[item]["waste_description"]:
icon = "mdi:recycle"
elif "YARD" in schedule[item]["waste_description"]:
icon = "mdi:leaf"
else:
icon = "mdi:trash-can"
entries.append(
Collection(
date=schedule[item]["date"],
t=schedule[item]["waste_type"],
icon=icon,
),
)

if self._method == 1: # Original logic
for item in schedule:
if "RECYCLE" in schedule[item]["waste_description"]:
icon = "mdi:recycle"
elif "YARD" in schedule[item]["waste_description"]:
icon = "mdi:leaf"
else:
icon = "mdi:trash-can"
entries.append(
Collection(
date=schedule[item]["date"],
t=schedule[item]["waste_type"],
icon=icon,
),
)
elif (
self._method == 2
): # Updated to report yard waste as a separate category to recycling
for item in schedule:
if "YARD" in schedule[item]["waste_description"]:
icon = "mdi:leaf"
schedule[item]["waste_type"] = "Yard Waste"
elif "RECYCLE" in schedule[item]["waste_description"]:
icon = "mdi:recycle"
elif "YARD" in schedule[item]["waste_description"]:
icon = "mdi:leaf"
else:
icon = "mdi:trash-can"
entries.append(
Collection(
date=schedule[item]["date"],
t=schedule[item]["waste_type"],
icon=icon,
),
)

return entries
44 changes: 42 additions & 2 deletions doc/source/republicservices_com.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,63 @@ waste_collection_schedule:
- name: republicservices_com
args:
street_address: STREET_ADDRESS
method: METHOD
```

### Configuration Variables

**street_address**
*(string) (required)*

## Example
**method**
*(int) (optional)*

_method: 1_

Waste type categories are returned as per the Republic Services entries. This is the default behaviour if no arg is provided.

method: 2

Recycling waste type categories described as Yard Waste are returned as a "Yard Waste" waste type rather than source "Recycling" waste type.

## Example (method: 1)

```yaml
waste_collection_schedule:
sources:
- name: republicservices_com
args:
street_address: "101 E Main St, Georgetown, KY 40324"
street_address: "8957 Park Meadows Dr, Elk Grove, CA 95624"
method: 1
```
```bash
2023-10-24 : Recycle [mdi:leaf]
2023-10-31 : Recycle [mdi:recycle]
2023-11-14 : Recycle [mdi:recycle]
2023-11-28 : Recycle [mdi:recycle]
2023-12-12 : Recycle [mdi:recycle]
2023-12-26 : Recycle [mdi:recycle]
2023-10-24 : Solid Waste [mdi:trash-can]
```

## Example (method: 2)
```yaml
waste_collection_schedule:
sources:
- name: republicservices_com
args:
street_address: "8957 Park Meadows Dr, Elk Grove, CA 95624"
method: 2
```
```bash
2023-10-24 : Yard Waste [mdi:leaf]
2023-10-31 : Recycle [mdi:recycle]
2023-11-14 : Recycle [mdi:recycle]
2023-11-28 : Recycle [mdi:recycle]
2023-12-12 : Recycle [mdi:recycle]
2023-12-26 : Recycle [mdi:recycle]
2023-10-24 : Solid Waste [mdi:trash-can]
```
## How to check the street address

The street address can be tested [here](https://republicservices.com).
Loading