Skip to content

Commit

Permalink
refactor ipswich_qld_gov_au
Browse files Browse the repository at this point in the history
  • Loading branch information
mampfes committed Apr 23, 2022
1 parent 312ef6c commit f54cc0d
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import datetime
import urllib
from html.parser import HTMLParser
import requests

import requests
from waste_collection_schedule import Collection

TITLE = "Ipswich City Council"
DESCRIPTION = "Source for Ipswich City Council rubbish collection."
URL = "https://www.ipswich.qld.gov.au/live/waste-and-recycling/bin-collection-calendar"
TEST_CASES = {
"Camira State School": {"street": "184-202 Old Logan Rd", "suburb": "Camira"},
"Random": {"street":"50 Brisbane Road", "suburb": "Redbank"}
"Random": {"street": "50 Brisbane Road", "suburb": "Redbank"},
}


ICONS = {
"Waste Bin": "mdi:trash-can",
"Recycle Bin": "mdi:recycle",
"FOGO Bin": "mdi:leaf",
}


def toDate(dateStr: str):
items = dateStr.split("-")
return datetime.date(int(items[1]), int(items[2]), int(items[3]))


class IpswichGovAuParser(HTMLParser):
def __init__(self):
super().__init__()
Expand Down Expand Up @@ -45,10 +54,10 @@ def handle_endtag(self, tag):
self._span_level -= 1

def handle_starttag(self, tag, attrs):

d = dict(attrs)
cls = d.get("class", "")

if tag == "li":
self._li_level += 1
if self._li_level == 1 and cls == "WBD-result-item":
Expand All @@ -65,30 +74,26 @@ def handle_starttag(self, tag, attrs):
if self._li_valid and self._span_level == 3 and cls == "WBD-bin-text":
self._load_bin = True


def handle_data(self, data):

if not self._li_valid:
return

if self._load_date:
self._load_date = False

items = data.strip().split("-")
self._loaded_date = datetime.date(int(items[0]), int(items[1]), int(items[2]))
self._loaded_date = datetime.date(
int(items[0]), int(items[1]), int(items[2])
)

if self._load_bin:
self._load_bin = False

if data == "Waste Bin":
self._entries.append(Collection(self._loaded_date, "Rubbish", icon="mdi:trash-can"))

if data == "Recycle Bin":
self._entries.append(Collection(self._loaded_date, "Recycling", icon="mdi:recycle"))

if data == "FOGO Bin":
self._entries.append(Collection(self._loaded_date, "Garden", icon="mdi:leaf"))

self._entries.append(
Collection(
self._loaded_date, data, icon=ICONS.get(data, "mdi:trash-can")
)
)


class Source:
Expand All @@ -104,13 +109,10 @@ def fetch(self):
"agendaResultLimit": "3",
"dateFormat": "yyyy-MM-dd",
"displayFormat": "agenda",
"address": f"{address}+QLD%2C+Australia"
"address": f"{address}+QLD%2C+Australia",
}

r = requests.get(
"https://console.whatbinday.com/api/search",
params=params
)
r = requests.get("https://console.whatbinday.com/api/search", params=params)
p = IpswichGovAuParser()
p.feed(r.text)
return p.entries
return p.entries

0 comments on commit f54cc0d

Please sign in to comment.