mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 06:05:57 +01:00
refactor biffaleicester_co_uk
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import json
|
||||
import datetime
|
||||
import time
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
@@ -15,30 +13,19 @@ TEST_CASES = {
|
||||
|
||||
API_URL = "https://biffaleicester.co.uk/wp-admin/admin-ajax.php"
|
||||
|
||||
API_ACTIONS = {
|
||||
"address_search": "get_uprn_api",
|
||||
"collection": "get_details_api"
|
||||
}
|
||||
API_ACTIONS = {"address_search": "get_uprn_api", "collection": "get_details_api"}
|
||||
|
||||
HEADERS = {
|
||||
"user-agent": "Mozilla/5.0",
|
||||
}
|
||||
|
||||
BINS = {
|
||||
"DW": {
|
||||
"icon": "mdi:trash-can",
|
||||
"alias": "Refuse"
|
||||
},
|
||||
"RY": {
|
||||
"icon": "mdi:recycle",
|
||||
"alias": "Recycling"
|
||||
},
|
||||
"GW": {
|
||||
"icon": "mdi:leaf",
|
||||
"alias": "Green Waste"
|
||||
}
|
||||
"DW": {"icon": "mdi:trash-can", "alias": "Refuse"},
|
||||
"RY": {"icon": "mdi:recycle", "alias": "Recycling"},
|
||||
"GW": {"icon": "mdi:leaf", "alias": "Green Waste"},
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, uprn=None, post_code=None, number=None):
|
||||
self._uprn = uprn
|
||||
@@ -48,46 +35,39 @@ class Source:
|
||||
def fetch(self):
|
||||
# Lookup UPRN
|
||||
if not self._uprn:
|
||||
p = {
|
||||
'action': API_ACTIONS["address_search"],
|
||||
'postcode': self._post_code
|
||||
}
|
||||
p = {"action": API_ACTIONS["address_search"], "postcode": self._post_code}
|
||||
r = requests.post(API_URL, headers=HEADERS, data=p)
|
||||
r.raise_for_status()
|
||||
data = r.json()
|
||||
addresses = data['anyType']
|
||||
addresses = data["anyType"]
|
||||
|
||||
for address in addresses:
|
||||
if address["UPRNAddress"].startswith(self._number + " "):
|
||||
self._uprn = address["UPRNID"]
|
||||
|
||||
if not self._uprn:
|
||||
raise Exception(f"Could not find address {self._post_code} {self._number}")
|
||||
raise Exception(
|
||||
f"Could not find address {self._post_code} {self._number}"
|
||||
)
|
||||
|
||||
# Get collections
|
||||
p = {
|
||||
'action': API_ACTIONS["collection"],
|
||||
'uprn': self._uprn
|
||||
}
|
||||
p = {"action": API_ACTIONS["collection"], "uprn": self._uprn}
|
||||
r = requests.post(API_URL, headers=HEADERS, data=p)
|
||||
r.raise_for_status()
|
||||
data = json.loads(r.text)
|
||||
collections = data['anyType']
|
||||
collections = r.json()["anyType"]
|
||||
|
||||
entries = []
|
||||
|
||||
for collection in collections:
|
||||
type = collection['ServiceMode']
|
||||
type = collection["ServiceMode"]
|
||||
props = BINS[type]
|
||||
|
||||
next_date = datetime.datetime.strptime(collection['ServiceDueDate'], "%d/%m/%y").date()
|
||||
next_date = datetime.datetime.strptime(
|
||||
collection["ServiceDueDate"], "%d/%m/%y"
|
||||
).date()
|
||||
|
||||
entries.append(
|
||||
Collection(
|
||||
date = next_date,
|
||||
t = props["alias"],
|
||||
icon = props["icon"]
|
||||
)
|
||||
Collection(date=next_date, t=props["alias"], icon=props["icon"])
|
||||
)
|
||||
|
||||
return entries
|
||||
|
||||
2
info.md
2
info.md
@@ -30,7 +30,7 @@ Waste collection schedules from service provider web sites are updated daily, de
|
||||
| Slovenia | Moji odpadki, Ljubljana |
|
||||
| Sweden | Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, VA Syd Sophämntning |
|
||||
| Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
|
||||
| United Kingdom | Amber Valley Borough Council, Ashfield District Council, Basingstoke and Deane Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, Liverpool City Council, London Borough of Bromley, London Borough of Lewisham, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wigan Council, Wiltshire Council, Wyre Forest District Council |
|
||||
| United Kingdom | Amber Valley Borough Council, Ashfield District Council, Basingstoke and Deane Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Leicester City Council, Lewes District Council, Liverpool City Council, London Borough of Bromley, London Borough of Lewisham, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wigan Council, Wiltshire Council, Wyre Forest District Council |
|
||||
| United States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |
|
||||
<!--End of country section-->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user