Skip to content

Commit

Permalink
refactor belmont_wa_gov_au
Browse files Browse the repository at this point in the history
  • Loading branch information
mampfes committed May 28, 2022
1 parent 6dfaf83 commit 0ee05c5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 102 deletions.
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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:
- --safe
- --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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
23 changes: 4 additions & 19 deletions doc/source/belmont_wa_gov_au.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

0 comments on commit 0ee05c5

Please sign in to comment.