mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 00:04:11 +01:00
Fix/remove shapely (#1723)
* Remove shapely dependency * Entries found from sector, not address * Instructions to find sector name from your address manually * Add province and update documents links * remove shapley from manifest.json + reformat montral_ca --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
@@ -477,7 +477,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [City of Peterborough, ON](/doc/ics/recollect.md) / peterborough.ca
|
||||
- [City of Vancouver](/doc/ics/recollect.md) / vancouver.ca
|
||||
- [London (ON)](/doc/source/recyclecoach_com.md) / london.ca
|
||||
- [Montreal](/doc/source/montreal_ca.md) / montreal.ca/info-collectes
|
||||
- [Montreal (QC)](/doc/source/montreal_ca.md) / montreal.ca/info-collectes
|
||||
- [Ottawa, Canada](/doc/ics/recollect.md) / ottawa.ca
|
||||
- [RM of Morris, MB](/doc/ics/recollect.md) / mwmenviro.ca
|
||||
- [Strathcona County, ON](/doc/ics/recollect.md) / strathcona.ca
|
||||
@@ -1031,7 +1031,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Gore, Invercargill & Southland](/doc/source/wastenet_org_nz.md) / wastenet.org.nz
|
||||
- [Hamilton City Council](/doc/source/hcc_govt_nz.md) / fightthelandfill.co.nz
|
||||
- [Horowhenua District Council](/doc/source/horowhenua_govt_nz.md) / horowhenua.govt.nz
|
||||
- [Hutt City Council](/doc/source/toogoodtowaste.md) / toogoodtowaste.co.nz
|
||||
- [Hutt City Council](/doc/source/toogoodtowaste_co_nz.md) / toogoodtowaste.co.nz
|
||||
- [Waipa District Council](/doc/source/waipa_nz.md) / waipadc.govt.nz
|
||||
- [Wellington City Council](/doc/source/wellington_govt_nz.md) / wellington.govt.nz
|
||||
</details>
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
"documentation": "https://github.com/mampfes/hacs_waste_collection_schedule#readme",
|
||||
"integration_type": "hub",
|
||||
"iot_class": "cloud_polling",
|
||||
"requirements": ["icalendar", "recurring_ical_events", "icalevents", "beautifulsoup4", "lxml", "shapely"],
|
||||
"version": "1.45.0"
|
||||
"requirements": ["icalendar", "recurring_ical_events", "icalevents", "beautifulsoup4", "lxml"],
|
||||
"version": "1.45.1"
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import requests
|
||||
from shapely.geometry import Point, shape
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
# Currently, Montreal does not offer an iCal/Webcal subscription method.
|
||||
@@ -12,13 +11,13 @@ from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
# The waste collection schedule is then interpreted from English natural language. Not every sector follows the same structure.
|
||||
# This method is not highly reliable but serves as an acceptable workaround until a better solution is provided by the city.
|
||||
|
||||
TITLE = "Montreal"
|
||||
TITLE = "Montreal (QC)"
|
||||
DESCRIPTION = "Source script for montreal.ca/info-collectes"
|
||||
URL = "https://montreal.ca/info-collectes"
|
||||
TEST_CASES = {
|
||||
"6280 Chambord": {"address": "6280 rue Chambord"},
|
||||
"2358 Monsabre": {"address": "2358 rue Monsabre"},
|
||||
"10785 Clark": {"address": "10785 rue Clark"},
|
||||
"Lasalle": {"sector": "LSL4"},
|
||||
"Mercier-Hochelaga": {"sector": "MHM_42-5_B"},
|
||||
"Ahuntsic": {"sector": "AC-2"},
|
||||
}
|
||||
|
||||
API_URL = [
|
||||
@@ -86,8 +85,8 @@ LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, address):
|
||||
self._address = address
|
||||
def __init__(self, sector):
|
||||
self._sector = sector
|
||||
|
||||
def get_collections(self, collection_day, weeks, start_date):
|
||||
collection_day = time.strptime(collection_day, "%A").tm_wday
|
||||
@@ -103,30 +102,6 @@ class Source:
|
||||
next_dates.append(next_collect)
|
||||
return next_dates
|
||||
|
||||
def get_latitude_longitude_point(self):
|
||||
# Get latitude & longitude of address
|
||||
url = "https://geocoder.cit.api.here.com/6.2/search.json"
|
||||
|
||||
params = {
|
||||
"gen": "9",
|
||||
"app_id": "pYZXmzEqjmR2DG66DRIr",
|
||||
"app_code": "T-Z-VT6e6I7IXGuqBfF_vQ",
|
||||
"country": "CAN",
|
||||
"state": "QC",
|
||||
"searchtext": self._address,
|
||||
"bbox": "45.39,-73.37;45.72,-74.00",
|
||||
}
|
||||
|
||||
r = requests.get(url, params=params)
|
||||
r.raise_for_status()
|
||||
|
||||
lat_long = r.json()["Response"]["View"][0]["Result"][0]["Location"][
|
||||
"DisplayPosition"
|
||||
]
|
||||
|
||||
# construct point based on lon/lat returned by geocoder
|
||||
return Point(lat_long["Longitude"], lat_long["Latitude"])
|
||||
|
||||
def parse_green(self, schedule_message):
|
||||
SOURCE_TYPE = "Green"
|
||||
days = []
|
||||
@@ -251,7 +226,7 @@ class Source:
|
||||
pass # Skip if the day is out of range for the month
|
||||
return entries
|
||||
|
||||
def get_data_by_source(self, source_type, url, point):
|
||||
def get_data_by_source(self, source_type, url):
|
||||
# Get waste collection zone by longitude and latitude
|
||||
|
||||
r = requests.get(url)
|
||||
@@ -260,11 +235,9 @@ class Source:
|
||||
schedule = r.json()
|
||||
entries = []
|
||||
|
||||
# check each polygon to see if it contains the point
|
||||
# check the information for the sector
|
||||
for feature in schedule["features"]:
|
||||
sector_shape = shape(feature["geometry"])
|
||||
|
||||
if not sector_shape.contains(point):
|
||||
if feature["properties"]["SECTEUR"] != self._sector:
|
||||
continue
|
||||
schedule_message = feature["properties"]["MESSAGE_EN"]
|
||||
|
||||
@@ -287,12 +260,10 @@ class Source:
|
||||
return entries
|
||||
|
||||
def fetch(self):
|
||||
point = self.get_latitude_longitude_point()
|
||||
|
||||
entries = []
|
||||
for source in API_URL:
|
||||
try:
|
||||
entries += self.get_data_by_source(source["type"], source["url"], point)
|
||||
entries += self.get_data_by_source(source["type"], source["url"])
|
||||
except Exception:
|
||||
# Probably because the natural language format does not match known formats.
|
||||
LOGGER.warning(
|
||||
|
||||
@@ -9,14 +9,25 @@ waste_collection_schedule:
|
||||
sources:
|
||||
- name: montreal_ca
|
||||
args:
|
||||
address: ADDRESS
|
||||
sector: SECTOR
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**address**
|
||||
**sector**
|
||||
*(string) (required)*
|
||||
|
||||
**How do I find my sector?**
|
||||
|
||||
- Download on your computer a [Montreal GeoJSON file](https://donnees.montreal.ca/dataset/2df0fa28-7a7b-46c6-912f-93b215bd201e/resource/5f3fb372-64e8-45f2-a406-f1614930305c/download/collecte-des-ordures-menageres.geojson)
|
||||
- Visit https://geojson.io/
|
||||
- Click on *Open* and select the Montreal GeoJSON file
|
||||
- Find your sector on the map
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
@@ -24,5 +35,5 @@ waste_collection_schedule:
|
||||
sources:
|
||||
- name: montreal_ca
|
||||
args:
|
||||
address: 2812, rue Monsabre
|
||||
address: MHM_41-1
|
||||
```
|
||||
|
||||
BIN
images/montreal_ca_helper.png
Normal file
BIN
images/montreal_ca_helper.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
@@ -9,5 +9,4 @@ recurring-ical-events>=2.0.2
|
||||
requests>=2.31.0
|
||||
urllib3>=2.0.7
|
||||
jinja2>=3.1.2
|
||||
lxml>=4.9.4
|
||||
shapely>=2.0.2
|
||||
lxml>=4.9.4
|
||||
Reference in New Issue
Block a user