mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
addressing comments from mampfes
This commit is contained in:
@@ -99,6 +99,7 @@ Currently the following service providers are supported:
|
||||
### New Zealand
|
||||
|
||||
- [Auckland](./doc/source/aucklandcouncil_govt_nz.md)
|
||||
- [Wellington](./dock/source/wellington_govt_nz.md)
|
||||
- [Christchurch](./doc/source/ccc_govt_nz.md)
|
||||
- [Gore, Invercargill & Southland](./doc/source/wastenet_org_nz.md)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
from html.parser import HTMLParser
|
||||
import json
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
@@ -11,43 +12,40 @@ DESCRIPTION = "Source for Wellington City Council."
|
||||
URL = "https://wellington.govt.nz"
|
||||
TEST_CASES = {
|
||||
"Chelsea St": {"streetName": "chelsea street"}, # Friday
|
||||
"Campbell St (ID Only)": {"streetId": "6515"}, # Wednesday
|
||||
# "Campbell St (ID Only)": {"streetId": "6515"}, # Wednesday
|
||||
"BAD StreetID": {"streetId":"1"}
|
||||
}
|
||||
|
||||
|
||||
ICON_MAP = {
|
||||
"Rubbish Collection": "mdi:trash-can",
|
||||
"Glass crate": "mdi:glass-fragile",
|
||||
"Wheelie bin or recycling bags":"mdi:recycle",
|
||||
}
|
||||
|
||||
PICTURE_MAP = {
|
||||
"Rubbish Collection": "https://wellington.govt.nz/assets/images/rubbish-recycling/rubbish-bag.png",
|
||||
"Glass crate": "https://wellington.govt.nz/assets/images/rubbish-recycling/glass-crate.png",
|
||||
"Wheelie bin or recycling bags":"https://wellington.govt.nz/assets/images/rubbish-recycling/wheelie-bin.png",
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, streetId= None, streetName= None):
|
||||
self._streetId = streetId
|
||||
self._streetName = streetName
|
||||
self._ics = ICS()
|
||||
|
||||
def get_icon(self, wasteType):
|
||||
if wasteType == "Rubbish Collection":
|
||||
return "mdi:trash-can"
|
||||
if wasteType == "Glass crate":
|
||||
return "mdi:glass-fragile"
|
||||
if wasteType == "Wheelie bin or recycling bags":
|
||||
return "mdi:recycle"
|
||||
return None
|
||||
|
||||
def get_image(self, wasteType):
|
||||
if wasteType == "Rubbish Collection":
|
||||
return "https://wellington.govt.nz/assets/images/rubbish-recycling/rubbish-bag.png"
|
||||
if wasteType == "Glass crate":
|
||||
return "https://wellington.govt.nz/assets/images/rubbish-recycling/glass-crate.png"
|
||||
if wasteType == "Wheelie bin or recycling bags":
|
||||
return "https://wellington.govt.nz/assets/images/rubbish-recycling/wheelie-bin.png"
|
||||
return None
|
||||
|
||||
|
||||
def fetch(self):
|
||||
# get token
|
||||
if self._streetName:
|
||||
import json
|
||||
url = "https://wellington.govt.nz/layouts/wcc/GeneralLayout.aspx/GetRubbishCollectionStreets"
|
||||
headers = requests.structures.CaseInsensitiveDict()
|
||||
headers["Origin"] = "https://wellington.govt.nz/rubbish-recycling-and-waste/when-to-put-out-your-rubbish-and-recycling"
|
||||
headers["Access-Control-Request-Method"] = "POST"
|
||||
headers["Content-Type"] = "application/json"
|
||||
headers = {
|
||||
"Origin":"https://wellington.govt.nz/rubbish-recycling-and-waste/when-to-put-out-your-rubbish-and-recycling",
|
||||
"Access-Control-Request-Method": "POST",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
data = {"partialStreetName":self._streetName}
|
||||
json_string = json.dumps(data)
|
||||
r = requests.post(url, headers=headers, data=json_string)
|
||||
@@ -57,14 +55,21 @@ class Source:
|
||||
if len(data["d"]) > 1:
|
||||
raise Exception(f"More then one result returned for {self._streetName}, be more specific or use StreetId instead")
|
||||
self._streetId = data["d"][0].get('Key')
|
||||
if self._streetId:
|
||||
|
||||
if not self._streetId:
|
||||
raise Exception(f"No StreetId Supplied")
|
||||
|
||||
url = "https://wellington.govt.nz/~/ical/"
|
||||
params = {"type":"recycling","streetId":self._streetId,"forDate": datetime.date.today()}
|
||||
r = requests.get(url, params=params)
|
||||
|
||||
if not r.text.startswith("BEGIN:VCALENDAR"):
|
||||
raise Exception(f"StreetID: {self._streetId} is not a valid streetID")
|
||||
|
||||
dates = self._ics.convert(r.text)
|
||||
entries = []
|
||||
for d in dates:
|
||||
for wasteType in d[1].split("&"):
|
||||
wasteType = wasteType.strip()
|
||||
entries.append(Collection(d[0], wasteType, picture=self.get_image(wasteType), icon=self.get_icon(wasteType)))
|
||||
entries.append(Collection(d[0], wasteType, picture=PICTURE_MAP[wasteType], icon=ICON_MAP[wasteType]))
|
||||
return entries
|
||||
|
||||
@@ -19,7 +19,7 @@ waste_collection_schedule:
|
||||
*(string)*<br>
|
||||
**streetId**<br>
|
||||
*(string)*<br>
|
||||
*One of the above is Required, you could use both, but not recommeded*
|
||||
*One of the above is Required*
|
||||
|
||||
## Example
|
||||
|
||||
@@ -45,6 +45,6 @@ The source argument is the either the street name or streetid number from Wellin
|
||||
|
||||
- Open your When to put out your rubbish and recycling page, and enter your address in the search box [on the Wellington City Council collection day finder](https://wellington.govt.nz/rubbish-recycling-and-waste/when-to-put-out-your-rubbish-and-recycling)
|
||||
- The "streetName" variable uses the same code that the search box uses to find the streetID from your street name, suburb. But like the search box you do not need to enter the full name if your text matches only one result. For example "Miramar" would get you two results for Miramar Ave, Miramar and Miramar North Road, Miramar and the script would error as it can only deal with one street per call, so you would need to write "Miramar Ave" or "Miramar Avenue" etc to get the right result.
|
||||
- If you are having issues with the script finding your street, or you can't get it to narrow the result without selection options on the Welington Council site, you can use the streetID paramater directly.
|
||||
- If you are having issues with the script finding your street, or you can't get it to narrow the result without selection options on the Wellington Council site, you can use the streetID parameter directly.
|
||||
- Once you have found your street on the Website, look at the Blue button which is meant to show you the next weeks collection info, if you hover over the button, right click and copy link, you should get back a URL e.g. https://wellington.govt.nz/rubbish-recycling-and-waste/when-to-put-out-your-rubbish-and-recycling/components/collection-search-results?streetId=8187&addWeeks=1
|
||||
- Look for the streetId paramter in the URL in the example link above, it is streetId= `8187`
|
||||
- Look for the streetId parameter in the URL in the example link above, it is streetId= `8187`
|
||||
|
||||
Reference in New Issue
Block a user