Skip to content

Commit

Permalink
Add toogoodtowaste.co.nz (#1700)
Browse files Browse the repository at this point in the history
* Add toogoodtowaste.co.nz

* script updates these files

* copy-paste wrong council

* reformatting + second wrong councyl copy

---------

Co-authored-by: 5ila5 <[email protected]>
  • Loading branch information
meringu and 5ila5 authored Jan 22, 2024
1 parent 89cde24 commit d529562
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +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
- [Waipa District Council](/doc/source/waipa_nz.md) / waipadc.govt.nz
- [Wellington City Council](/doc/source/wellington_govt_nz.md) / wellington.govt.nz
</details>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import datetime
import json
import time

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Hutt City Council"
DESCRIPTION = "Source for Hutt City Council."
URL = "https://www.toogoodtowaste.co.nz/"
TEST_CASES = {
"Bus Barns": {"address": "493 Muritai Road EASTBOURNE"}, # Monday
"Council": {"address": "30 Laings Road HUTT CENTRAL"}, # Tuesday
}

WASTE_TYPE_MAP = {
"red": "Red bin",
"yellow": "Yellow bin",
"blue": "Blue crate",
"green": "Green waste bin",
}

ICON_MAP = {
"red": "mdi:trash-can",
"yellow": "mdi:recycle",
"blue": "mdi:glass-fragile",
"green": "mdi:tree",
}

PICTURE_MAP = {
"red": f"{URL}__data/assets/image/0024/1779/bin-red.png",
"yellow": f"{URL}__data/assets/image/0017/1781/bin-yellow.png",
"blue": f"{URL}__data/assets/image/0016/1780/bin-blue.png",
"green": f"{URL}__data/assets/image/0018/1782/bin-green.png",
}


class Source:
def __init__(self, address):
self._address = address

def fetch(self):
ts = round(time.time() * 1000)
encoded_address = requests.utils.quote(self._address)
url = f"{URL}_designs/integrations/address-finder/addressdata.json?query={encoded_address}&timestamp={ts}"
r = requests.get(url)
data = json.loads(r.text)

filtered = [
res["attributes"]
for res in data
if res["attributes"]["address"] == self._address
]
if len(filtered) == 0:
raise Exception(f"No result found for address {self._address}")
if len(filtered) > 1:
raise Exception(
f"More then one result returned for address {self._address}."
)

result = filtered[0]
bin_list = json.loads(result["bin_list"])

entries = []
for bin in bin_list:
entries.append(
Collection(
datetime.date(*map(int, result["next_collection_date"].split("-"))),
WASTE_TYPE_MAP.get(bin, bin),
picture=PICTURE_MAP.get(bin),
icon=ICON_MAP.get(bin),
)
)

return entries
28 changes: 28 additions & 0 deletions doc/source/toogoodtowaste_co_nz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Hutt City Council

Support for schedules provided by [Hutt City Council](https://toogoodtowaste.co.nz/).

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: toogoodtowaste_co_nz
args:
address: 30 Laings Road HUTT CENTRAL # see 'How to get the source argument below'
```
### Configuration Variables
**address**
*(string)*
## How to get the source argument
The source argument is the address as is appears when searched on https://toogoodtowaste.co.nz:
- Search for you address on https://toogoodtowaste.co.nz
- Select your address from the dropdown
- Copy your address from the text box
The casing must match exactly.
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Lithuania | Kauno švara |
| Luxembourg | Esch-sur-Alzette |
| Netherlands | ACV Group, Alpen an den Rijn, Area Afval, Avalex, Avri, Bar Afvalbeheer, Circulus, Cyclus NV, Dar, Den Haag, GAD, Gemeente Almere, Gemeente Berkelland, Gemeente Cranendonck, Gemeente Hellendoorn, Gemeente Lingewaard, Gemeente Meppel, Gemeente Middelburg + Vlissingen, Gemeente Peel en Maas, Gemeente Schouwen-Duiveland, Gemeente Sudwest-Fryslan, Gemeente Venray, Gemeente Voorschoten, Gemeente Waalre, Gemeente Westland, HVC Groep, Meerlanden, Mijn Blink, PreZero, Purmerend, RAD BV, Reinis, Spaarnelanden, Twente Milieu, Waardlanden, Ximmio, ZRD |
| New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Waipa District Council, Wellington City Council |
| New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Hutt City Council, Waipa District Council, Wellington City Council |
| Norway | BIR (Bergensområdets Interkommunale Renovasjonsselskap), IRiS, Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Sandnes Kommune, Stavanger Kommune, Trondheim |
| Poland | Ecoharmonogram, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław |
| Slovenia | Moji odpadki, Ljubljana |
Expand Down

0 comments on commit d529562

Please sign in to comment.