mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +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 Peterborough, ON](/doc/ics/recollect.md) / peterborough.ca
|
||||||
- [City of Vancouver](/doc/ics/recollect.md) / vancouver.ca
|
- [City of Vancouver](/doc/ics/recollect.md) / vancouver.ca
|
||||||
- [London (ON)](/doc/source/recyclecoach_com.md) / london.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
|
- [Ottawa, Canada](/doc/ics/recollect.md) / ottawa.ca
|
||||||
- [RM of Morris, MB](/doc/ics/recollect.md) / mwmenviro.ca
|
- [RM of Morris, MB](/doc/ics/recollect.md) / mwmenviro.ca
|
||||||
- [Strathcona County, ON](/doc/ics/recollect.md) / strathcona.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
|
- [Gore, Invercargill & Southland](/doc/source/wastenet_org_nz.md) / wastenet.org.nz
|
||||||
- [Hamilton City Council](/doc/source/hcc_govt_nz.md) / fightthelandfill.co.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
|
- [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
|
- [Waipa District Council](/doc/source/waipa_nz.md) / waipadc.govt.nz
|
||||||
- [Wellington City Council](/doc/source/wellington_govt_nz.md) / wellington.govt.nz
|
- [Wellington City Council](/doc/source/wellington_govt_nz.md) / wellington.govt.nz
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
@@ -6,6 +6,6 @@
|
|||||||
"documentation": "https://github.com/mampfes/hacs_waste_collection_schedule#readme",
|
"documentation": "https://github.com/mampfes/hacs_waste_collection_schedule#readme",
|
||||||
"integration_type": "hub",
|
"integration_type": "hub",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"requirements": ["icalendar", "recurring_ical_events", "icalevents", "beautifulsoup4", "lxml", "shapely"],
|
"requirements": ["icalendar", "recurring_ical_events", "icalevents", "beautifulsoup4", "lxml"],
|
||||||
"version": "1.45.0"
|
"version": "1.45.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import time
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from shapely.geometry import Point, shape
|
|
||||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||||
|
|
||||||
# Currently, Montreal does not offer an iCal/Webcal subscription method.
|
# 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.
|
# 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.
|
# 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"
|
DESCRIPTION = "Source script for montreal.ca/info-collectes"
|
||||||
URL = "https://montreal.ca/info-collectes"
|
URL = "https://montreal.ca/info-collectes"
|
||||||
TEST_CASES = {
|
TEST_CASES = {
|
||||||
"6280 Chambord": {"address": "6280 rue Chambord"},
|
"Lasalle": {"sector": "LSL4"},
|
||||||
"2358 Monsabre": {"address": "2358 rue Monsabre"},
|
"Mercier-Hochelaga": {"sector": "MHM_42-5_B"},
|
||||||
"10785 Clark": {"address": "10785 rue Clark"},
|
"Ahuntsic": {"sector": "AC-2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
API_URL = [
|
API_URL = [
|
||||||
@@ -86,8 +85,8 @@ LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class Source:
|
class Source:
|
||||||
def __init__(self, address):
|
def __init__(self, sector):
|
||||||
self._address = address
|
self._sector = sector
|
||||||
|
|
||||||
def get_collections(self, collection_day, weeks, start_date):
|
def get_collections(self, collection_day, weeks, start_date):
|
||||||
collection_day = time.strptime(collection_day, "%A").tm_wday
|
collection_day = time.strptime(collection_day, "%A").tm_wday
|
||||||
@@ -103,30 +102,6 @@ class Source:
|
|||||||
next_dates.append(next_collect)
|
next_dates.append(next_collect)
|
||||||
return next_dates
|
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):
|
def parse_green(self, schedule_message):
|
||||||
SOURCE_TYPE = "Green"
|
SOURCE_TYPE = "Green"
|
||||||
days = []
|
days = []
|
||||||
@@ -251,7 +226,7 @@ class Source:
|
|||||||
pass # Skip if the day is out of range for the month
|
pass # Skip if the day is out of range for the month
|
||||||
return entries
|
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
|
# Get waste collection zone by longitude and latitude
|
||||||
|
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
@@ -260,11 +235,9 @@ class Source:
|
|||||||
schedule = r.json()
|
schedule = r.json()
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
# check each polygon to see if it contains the point
|
# check the information for the sector
|
||||||
for feature in schedule["features"]:
|
for feature in schedule["features"]:
|
||||||
sector_shape = shape(feature["geometry"])
|
if feature["properties"]["SECTEUR"] != self._sector:
|
||||||
|
|
||||||
if not sector_shape.contains(point):
|
|
||||||
continue
|
continue
|
||||||
schedule_message = feature["properties"]["MESSAGE_EN"]
|
schedule_message = feature["properties"]["MESSAGE_EN"]
|
||||||
|
|
||||||
@@ -287,12 +260,10 @@ class Source:
|
|||||||
return entries
|
return entries
|
||||||
|
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
point = self.get_latitude_longitude_point()
|
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for source in API_URL:
|
for source in API_URL:
|
||||||
try:
|
try:
|
||||||
entries += self.get_data_by_source(source["type"], source["url"], point)
|
entries += self.get_data_by_source(source["type"], source["url"])
|
||||||
except Exception:
|
except Exception:
|
||||||
# Probably because the natural language format does not match known formats.
|
# Probably because the natural language format does not match known formats.
|
||||||
LOGGER.warning(
|
LOGGER.warning(
|
||||||
|
|||||||
@@ -9,14 +9,25 @@ waste_collection_schedule:
|
|||||||
sources:
|
sources:
|
||||||
- name: montreal_ca
|
- name: montreal_ca
|
||||||
args:
|
args:
|
||||||
address: ADDRESS
|
sector: SECTOR
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuration Variables
|
### Configuration Variables
|
||||||
|
|
||||||
**address**
|
**sector**
|
||||||
*(string) (required)*
|
*(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
|
## Example
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -24,5 +35,5 @@ waste_collection_schedule:
|
|||||||
sources:
|
sources:
|
||||||
- name: montreal_ca
|
- name: montreal_ca
|
||||||
args:
|
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 |
@@ -10,4 +10,3 @@ requests>=2.31.0
|
|||||||
urllib3>=2.0.7
|
urllib3>=2.0.7
|
||||||
jinja2>=3.1.2
|
jinja2>=3.1.2
|
||||||
lxml>=4.9.4
|
lxml>=4.9.4
|
||||||
shapely>=2.0.2
|
|
||||||
Reference in New Issue
Block a user