mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
improve recyclecaoch_com
Providees Default params for the GUI Throws SourceArgumentNotFoundWithSuggestions for invalid streets so the GUI suggests alternatives
This commit is contained in:
@@ -3479,7 +3479,10 @@
|
||||
{
|
||||
"title": "Aurora (ON)",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Aurora",
|
||||
"state": "Ontario"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
@@ -3563,13 +3566,19 @@
|
||||
{
|
||||
"title": "Kawartha Lakes (ON)",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Kawartha Lakes",
|
||||
"state": "Ontario"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
"title": "London (ON)",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "London",
|
||||
"state": "Ontario"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
@@ -3647,7 +3656,10 @@
|
||||
{
|
||||
"title": "Vaughan (ON)",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Vaughan",
|
||||
"state": "Ontario"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
@@ -11563,7 +11575,10 @@
|
||||
{
|
||||
"title": "Albuquerque, New Mexico, USA",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Albuquerque",
|
||||
"state": "New Mexico"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
@@ -11629,7 +11644,10 @@
|
||||
{
|
||||
"title": "Louisville, Kentucky, USA",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Louisville",
|
||||
"state": "Kentucky"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
@@ -11641,13 +11659,19 @@
|
||||
{
|
||||
"title": "Newark, Delaware, USA",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Newark",
|
||||
"state": "Delaware"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
"title": "Olympia, Washington, USA",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Olympia",
|
||||
"state": "Washington"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
@@ -11679,7 +11703,10 @@
|
||||
{
|
||||
"title": "Tucson, Arizona, USA",
|
||||
"module": "recyclecoach_com",
|
||||
"default_params": {},
|
||||
"default_params": {
|
||||
"city": "Tucson",
|
||||
"state": "Arizona"
|
||||
},
|
||||
"id": "recyclecoach_com"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -3,6 +3,10 @@ from datetime import datetime
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
from waste_collection_schedule.exceptions import (
|
||||
SourceArgumentNotFound,
|
||||
SourceArgumentNotFoundWithSuggestions,
|
||||
)
|
||||
|
||||
TITLE = "Recycle Coach"
|
||||
DESCRIPTION = "Source loader for recyclecoach.com"
|
||||
@@ -19,26 +23,46 @@ EXTRA_INFO = [
|
||||
{
|
||||
"title": "Albuquerque, New Mexico, USA",
|
||||
"url": "https://recyclecoach.com/cities/usa-nm-city-of-albuquerque/",
|
||||
"default_params": {"city": "Albuquerque", "state": "New Mexico"},
|
||||
},
|
||||
{
|
||||
"title": "Tucson, Arizona, USA",
|
||||
"url": "https://recyclecoach.com/cities/usa-az-city-of-tucson/",
|
||||
"default_params": {"city": "Tucson", "state": "Arizona"},
|
||||
},
|
||||
{
|
||||
"title": "Olympia, Washington, USA",
|
||||
"url": "https://recyclecoach.com/cities/usa-wa-city-of-olympia/",
|
||||
"default_params": {"city": "Olympia", "state": "Washington"},
|
||||
},
|
||||
{
|
||||
"title": "Newark, Delaware, USA",
|
||||
"url": "https://recyclecoach.com/cities/usa-de-city-of-newark/",
|
||||
"default_params": {"city": "Newark", "state": "Delaware"},
|
||||
},
|
||||
{
|
||||
"title": "Louisville, Kentucky, USA",
|
||||
"url": "https://recyclecoach.com/cities/usa-ky-city-of-louisville/",
|
||||
"default_params": {"city": "Louisville", "state": "Kentucky"},
|
||||
},
|
||||
{
|
||||
"title": "London (ON)",
|
||||
"url": "https://london.ca/",
|
||||
"country": "ca",
|
||||
"default_params": {"city": "London", "state": "Ontario"},
|
||||
},
|
||||
{
|
||||
"title": "Aurora (ON)",
|
||||
"url": "https://www.aurora.ca/",
|
||||
"country": "ca",
|
||||
"default_params": {"city": "Aurora", "state": "Ontario"},
|
||||
},
|
||||
{
|
||||
"title": "Vaughan (ON)",
|
||||
"url": "https://www.vaughan.ca/",
|
||||
"country": "ca",
|
||||
"default_params": {"city": "Vaughan", "state": "Ontario"},
|
||||
},
|
||||
{"title": "London (ON)", "url": "https://london.ca/", "country": "ca"},
|
||||
{"title": "Aurora (ON)", "url": "https://www.aurora.ca/", "country": "ca"},
|
||||
{"title": "Vaughan (ON)", "url": "https://www.vaughan.ca/", "country": "ca"},
|
||||
{
|
||||
"title": "Richmond Hill (ON)",
|
||||
"url": "https://www.richmondhill.ca/",
|
||||
@@ -48,6 +72,7 @@ EXTRA_INFO = [
|
||||
"title": "Kawartha Lakes (ON)",
|
||||
"url": "https://www.kawarthalakes.ca/",
|
||||
"country": "ca",
|
||||
"default_params": {"city": "Kawartha Lakes", "state": "Ontario"},
|
||||
},
|
||||
]
|
||||
|
||||
@@ -138,6 +163,7 @@ class Source:
|
||||
raise Exception(
|
||||
"Found your city, but it is not yet supported fully by recycle coach."
|
||||
)
|
||||
return
|
||||
|
||||
elif len(city_data["cities"]) > 1:
|
||||
for city in city_data["cities"]:
|
||||
@@ -145,12 +171,10 @@ class Source:
|
||||
self.project_id = city["project_id"]
|
||||
self.district_id = city["district_id"]
|
||||
self.stage = float(city["stage"])
|
||||
return True
|
||||
return
|
||||
|
||||
# not sure what to do with ambiguity here
|
||||
# print(json.dumps(city_data['cities'], indent=4))
|
||||
raise Exception(
|
||||
"Could not determine district or project, Debug here to find your discrict and project_id"
|
||||
"Could not determine district or project, This probably means your city, state is wrong or not supported."
|
||||
)
|
||||
|
||||
def _lookup_zones_with_geo(self):
|
||||
@@ -158,8 +182,10 @@ class Source:
|
||||
res = requests.get(pos_finder)
|
||||
lat = None
|
||||
pos_data = res.json()
|
||||
streets = []
|
||||
for pos_res in pos_data:
|
||||
streetpart = self._format_key(pos_res["address"]).split(",")[0]
|
||||
streets.append(pos_res["address"].strip().split(",")[0])
|
||||
|
||||
if streetpart in self.street:
|
||||
lat = pos_res["lat"]
|
||||
@@ -167,7 +193,16 @@ class Source:
|
||||
break
|
||||
|
||||
if not lat:
|
||||
raise Exception("Unable to find zone")
|
||||
if streets:
|
||||
raise SourceArgumentNotFoundWithSuggestions(
|
||||
"street",
|
||||
self.street,
|
||||
streets,
|
||||
)
|
||||
raise SourceArgumentNotFound(
|
||||
"street",
|
||||
self.street,
|
||||
)
|
||||
|
||||
zone_finder = f"https://pkg.my-waste.mobi/get_zones?project_id={self.project_id}&district_id={self.district_id}&lat={lat}&lng={lng}"
|
||||
res = requests.get(zone_finder)
|
||||
@@ -182,14 +217,23 @@ class Source:
|
||||
zone_data = res.json()
|
||||
if "results" not in zone_data:
|
||||
return self._lookup_zones_with_geo()
|
||||
streets = []
|
||||
for zone_res in zone_data["results"]:
|
||||
streetpart = self._format_key(zone_res["address"]).split(",")[0]
|
||||
|
||||
streets.append(zone_res["address"].strip().split(",")[0])
|
||||
if streetpart in self.street:
|
||||
self.zone_id = self._build_zone_string(zone_res["zones"])
|
||||
return self.zone_id
|
||||
|
||||
raise Exception("Unable to find zone")
|
||||
if streets:
|
||||
raise SourceArgumentNotFoundWithSuggestions(
|
||||
"street",
|
||||
self.street,
|
||||
streets,
|
||||
)
|
||||
raise SourceArgumentNotFound(
|
||||
"street",
|
||||
self.street,
|
||||
)
|
||||
|
||||
def _build_zone_string(self, z_match):
|
||||
"""Take matching json and build a format zone-z12312-z1894323-z8461."""
|
||||
|
||||
Reference in New Issue
Block a user