mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 02:04:22 +01:00
refactor belmont_wa_gov_au
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
repos:
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v2.3.0
|
||||
rev: v2.32.1
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py37-plus]
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 19.10b0
|
||||
rev: 22.3.0
|
||||
hooks:
|
||||
- id: black
|
||||
args:
|
||||
@@ -13,7 +13,7 @@ repos:
|
||||
- --quiet
|
||||
files: ^((custom_components|script|tests)/.+)?[^/]+\.py$
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
rev: v1.16.0
|
||||
rev: v2.1.0
|
||||
hooks:
|
||||
- id: codespell
|
||||
args:
|
||||
@@ -22,7 +22,7 @@ repos:
|
||||
- --quiet-level=2
|
||||
exclude_types: [csv, json]
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.8.1
|
||||
rev: 3.9.2
|
||||
hooks:
|
||||
- id: flake8
|
||||
args:
|
||||
@@ -32,7 +32,7 @@ repos:
|
||||
- pydocstyle==5.0.2
|
||||
files: ^(custom_components|script|tests)/.+\.py$
|
||||
- repo: https://github.com/PyCQA/bandit
|
||||
rev: 1.6.2
|
||||
rev: 1.7.4
|
||||
hooks:
|
||||
- id: bandit
|
||||
args:
|
||||
@@ -41,17 +41,17 @@ repos:
|
||||
- --configfile=tests/bandit.yaml
|
||||
files: ^(custom_components|script|tests)/.+\.py$
|
||||
- repo: https://github.com/pre-commit/mirrors-isort
|
||||
rev: v4.3.21
|
||||
rev: v5.10.1
|
||||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.4.0
|
||||
rev: v4.2.0
|
||||
hooks:
|
||||
- id: check-executables-have-shebangs
|
||||
stages: [manual]
|
||||
- id: check-json
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v0.901
|
||||
rev: v0.960
|
||||
hooks:
|
||||
- id: mypy
|
||||
additional_dependencies: ["types-requests"]
|
||||
|
||||
@@ -1,75 +1,68 @@
|
||||
from audioop import add
|
||||
import datetime
|
||||
import json
|
||||
|
||||
import requests
|
||||
from requests.utils import requote_uri
|
||||
from waste_collection_schedule import Collection
|
||||
|
||||
TITLE = "Belmont City Council"
|
||||
DESCRIPTION = "Source for Belmont City Council rubbish collection."
|
||||
URL = "https://www.belmont.wa.gov.au/"
|
||||
TEST_CASES = {
|
||||
"PETstock Belmont": {
|
||||
"post_code": "6104",
|
||||
"suburb": "Belmont",
|
||||
"street_name": "Abernethy Rd",
|
||||
"street_number": "196",
|
||||
},
|
||||
"Belgravia Medical Centre": {
|
||||
"post_code": "6105",
|
||||
"suburb": "Cloverdale",
|
||||
"street_name": "Belgravia St",
|
||||
"street_number": "374",
|
||||
},
|
||||
"IGA Rivervale": {
|
||||
"post_code": "6103",
|
||||
"suburb": "Rivervale",
|
||||
"street_name": "Kooyong Rd",
|
||||
"street_number": "126",
|
||||
},
|
||||
}
|
||||
|
||||
class Source:
|
||||
def __init__(
|
||||
self, post_code: str, suburb: str, street_name: str, street_number: str
|
||||
):
|
||||
self.post_code = post_code
|
||||
self.suburb = suburb
|
||||
self.street_name = street_name
|
||||
self.street_number = street_number
|
||||
|
||||
def fetch(self):
|
||||
|
||||
addressrequest = requests.get("https://www.belmont.wa.gov.au/api/intramaps/getaddresses?key="+str(self.street_number)+"%20"+self.street_name+"%20"+self.suburb+"%20"+str(self.post_code)).json()
|
||||
|
||||
for array in addressrequest:
|
||||
mapkey = str(array["mapkey"])
|
||||
dbkey = str(array["dbkey"])
|
||||
|
||||
|
||||
mapdbkeyurl = "https://www.belmont.wa.gov.au/api/intramaps/getpropertydetailswithlocalgov?mapkey="+mapkey+"&dbkey="+dbkey
|
||||
|
||||
collectionrequest = requests.get(mapdbkeyurl).json()
|
||||
|
||||
data = collectionrequest["data"]
|
||||
|
||||
entries = []
|
||||
|
||||
entries.append(
|
||||
Collection(
|
||||
date=datetime.datetime.strptime(data["BinDayGeneralWasteFormatted"], "%Y-%m-%dT%H:%M:%S").date(),
|
||||
t="General Waste",
|
||||
icon="mdi:trash-can",
|
||||
)
|
||||
)
|
||||
|
||||
entries.append(
|
||||
Collection(
|
||||
date=datetime.datetime.strptime(data["BinDayRecyclingFormatted"], "%Y-%m-%dT%H:%M:%S").date(),
|
||||
t="Recycling",
|
||||
icon="mdi:recycle",
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
import datetime
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection
|
||||
|
||||
TITLE = "Belmont City Council"
|
||||
DESCRIPTION = "Source for Belmont City Council rubbish collection."
|
||||
URL = "https://www.belmont.wa.gov.au/"
|
||||
TEST_CASES = {
|
||||
"PETstock Belmont": {"address": "196 Abernethy Road Belmont 6104"},
|
||||
"Belgravia Medical Centre": {"address": "374 Belgravia Street Cloverdale 6105"},
|
||||
"IGA Rivervale": {"address": "126 Kooyong Road Rivervale 6103"},
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, address: str):
|
||||
self._address = address
|
||||
|
||||
def fetch(self):
|
||||
params = {"key": self._address}
|
||||
r = requests.get(
|
||||
"https://www.belmont.wa.gov.au/api/intramaps/getaddresses", params=params
|
||||
)
|
||||
r.raise_for_status()
|
||||
j = r.json()
|
||||
|
||||
if len(j) == 0:
|
||||
raise Exception("address not found")
|
||||
|
||||
if len(j) > 1:
|
||||
raise Exception("multiple addresses found")
|
||||
|
||||
params = {"mapkey": j[0]["mapkey"], "dbkey": j[0]["dbkey"]}
|
||||
r = requests.get(
|
||||
"https://www.belmont.wa.gov.au/api/intramaps/getpropertydetailswithlocalgov",
|
||||
params=params,
|
||||
)
|
||||
r.raise_for_status()
|
||||
data = r.json()["data"]
|
||||
|
||||
entries = []
|
||||
|
||||
# get general waste
|
||||
date = datetime.datetime.strptime(
|
||||
data["BinDayGeneralWasteFormatted"], "%Y-%m-%dT%H:%M:%S"
|
||||
).date()
|
||||
entries.append(
|
||||
Collection(
|
||||
date=date,
|
||||
t="General Waste",
|
||||
icon="mdi:trash-can",
|
||||
)
|
||||
)
|
||||
|
||||
# get recycling
|
||||
date = datetime.datetime.strptime(
|
||||
data["BinDayRecyclingFormatted"], "%Y-%m-%dT%H:%M:%S"
|
||||
).date()
|
||||
entries.append(
|
||||
Collection(
|
||||
date=date,
|
||||
t="Recycling",
|
||||
icon="mdi:recycle",
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
|
||||
@@ -9,24 +9,12 @@ waste_collection_schedule:
|
||||
sources:
|
||||
- name: belmont_wa_gov_au
|
||||
args:
|
||||
post_code: POST_CODE
|
||||
suburb: SUBURB
|
||||
street_name: STREET_NAME
|
||||
street_number: STREET_NUMBER
|
||||
address: ADDRESS
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**post_code**<br>
|
||||
*(string) (required)*
|
||||
|
||||
**suburb**<br>
|
||||
*(string) (required)*
|
||||
|
||||
**street_name**<br>
|
||||
*(string) (required)*
|
||||
|
||||
**street_number**<br>
|
||||
**address**<br>
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
@@ -36,12 +24,9 @@ waste_collection_schedule:
|
||||
sources:
|
||||
- name: belmont_wa_gov_au
|
||||
args:
|
||||
post_code: 6104
|
||||
suburb: Belmont
|
||||
street_name: Abernethy Rd
|
||||
street_number: 196
|
||||
address: 196 Abernethy Road Belmont 6104
|
||||
```
|
||||
|
||||
## How to get the source arguments
|
||||
|
||||
Visit the [Belmont City Council Waste and Recycling](https://www.belmont.wa.gov.au/live/at-your-place/bins,-waste-and-recycling) page and search for your address. The arguments should exactly match the results shown for Post Code, Suburb, Street and number portion of the Property.
|
||||
Visit the [Belmont City Council Waste and Recycling](https://www.belmont.wa.gov.au/live/at-your-place/bins,-waste-and-recycling) page and search for your address. The arguments should exactly match the results of the property.
|
||||
Reference in New Issue
Block a user