mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 05:06:33 +01:00
Added Lisburn and Castlereagh City Council (#923)
* Added Lisburn and Castlereagh City Council * tidied a couple of things up * handling house number as int * updated example * updated the other examples * fixed up the docs * more doc fixes * typo fix (l 85, now 89) and reformatting --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
@@ -685,6 +685,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Huntingdonshire District Council](/doc/source/huntingdonshire_gov_uk.md) / huntingdonshire.gov.uk
|
||||
- [Leicester City Council](/doc/source/biffaleicester_co_uk.md) / leicester.gov.uk
|
||||
- [Lewes District Council](/doc/source/environmentfirst_co_uk.md) / lewes-eastbourne.gov.uk
|
||||
- [Lisburn and Castlereagh City Council](/doc/source/lisburn_castlereagh_gov_uk.md) / lisburncastlereagh.gov.uk
|
||||
- [Liverpool City Council](/doc/source/liverpool_gov_uk.md) / liverpool.gov.uk
|
||||
- [London Borough of Bexley](/doc/source/bexley_gov_uk.md) / bexley.gov.uk
|
||||
- [London Borough of Bromley](/doc/source/bromley_gov_uk.md) / bromley.gov.uk
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import requests
|
||||
import bs4
|
||||
import difflib
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from waste_collection_schedule import Collection
|
||||
|
||||
# Title will show up in README.md and info.md
|
||||
TITLE = "Lisburn and Castlereagh City Council"
|
||||
# Describe your source
|
||||
DESCRIPTION = "Source for the Lisburn and Castlereagh City Council"
|
||||
# Insert url to service homepage. URL will show up in README.md and info.md
|
||||
URL = "https://lisburncastlereagh.gov.uk/"
|
||||
TEST_CASES = {
|
||||
"Test_001": {"postcode": "BT28 1AG", "house_number": "19A"},
|
||||
"Test_002": {"postcode": "BT26 6AB", "house_number": "31"},
|
||||
"Test_003": {"postcode": "BT26 6AB", "house_number": 15},
|
||||
"Test_004": {"property_id": "DYYSm8Ls8XxGi3Nq"},
|
||||
"Test_005": {"property_id": "ZJat6DWG1Lp95xp1"},
|
||||
}
|
||||
|
||||
API_URL = "https://lisburn.isl-fusion.com"
|
||||
ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons
|
||||
"ResidualBin": "mdi:trash-can",
|
||||
"RecycleBin": "mdi:recycle",
|
||||
"BrownBin": "mdi:leaf",
|
||||
}
|
||||
NICE_NAMES = {
|
||||
"ResidualBin": "Refuse",
|
||||
"RecycleBin": "Recycling",
|
||||
"BrownBin": "Garden",
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
# argX correspond to the args dict in the source configuration
|
||||
def __init__(self, property_id=None, postcode=None, house_number=None):
|
||||
self._property_id = property_id
|
||||
self._postcode = postcode
|
||||
self._house_number = house_number
|
||||
|
||||
if not any([self._property_id, self._postcode and self._house_number]):
|
||||
raise ValueError("Must provide either a property ID or both the Postcode and House Number")
|
||||
|
||||
def fetch(self):
|
||||
session = requests.Session()
|
||||
|
||||
if not self._property_id:
|
||||
search_url = f"{API_URL}/address/{self._postcode}"
|
||||
response = session.get(search_url)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
address_list = response.json().get("html")
|
||||
except:
|
||||
raise ValueError(f"No data found for {self._postcode}")
|
||||
|
||||
soup = bs4.BeautifulSoup(address_list, features="html.parser")
|
||||
|
||||
address_by_id = {}
|
||||
for li in soup.findAll("li"):
|
||||
link = li.findAll("a")[0]
|
||||
property_id = link.attrs["href"].replace("/view", "").replace("/", "")
|
||||
address = link.text
|
||||
address_by_id[property_id] = address
|
||||
|
||||
all_addresses = list(address_by_id.values())
|
||||
|
||||
common = difflib.SequenceMatcher(a=all_addresses[0], b=all_addresses[1]).find_longest_match()
|
||||
to_be_removed = all_addresses[0][common.a:common.a+common.size]
|
||||
|
||||
ids_by_house_number = {
|
||||
address.replace(to_be_removed, ""): property_id for property_id, address in address_by_id.items()
|
||||
}
|
||||
|
||||
self._property_id = ids_by_house_number.get(str(self._house_number))
|
||||
|
||||
if not self._property_id:
|
||||
raise ValueError(f"Property not found for house number {self._house_number}")
|
||||
|
||||
today = datetime.today().date()
|
||||
calendar_url = f"{API_URL}/calendar/{self._property_id}/{today.strftime('%Y-%m-%d')}"
|
||||
response = session.get(calendar_url)
|
||||
response.raise_for_status()
|
||||
|
||||
try:
|
||||
next_collections = response.json().get("nextCollections")
|
||||
except:
|
||||
raise ValueError("No collection data in response")
|
||||
|
||||
entries = [] # List that holds collection schedule
|
||||
|
||||
for collection in next_collections["collections"].values():
|
||||
collection_date = datetime.strptime(collection["date"], "%Y-%m-%d").date()
|
||||
|
||||
for bin in collection["collections"].values():
|
||||
entries.append(
|
||||
Collection(
|
||||
date=collection_date,
|
||||
t=NICE_NAMES.get(bin["name"]),
|
||||
icon=ICON_MAP.get(bin["name"])
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
56
doc/source/lisburn_castlereagh_gov_uk.md
Normal file
56
doc/source/lisburn_castlereagh_gov_uk.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Lisburn and Castlereagh City Council
|
||||
|
||||
Support for schedules provided by [Lisburn and Castlereagh City Council](https://www.lisburncastlereagh.gov.uk/resident/bins-and-recycling/household-waste/collection-days-and-holiday-information), serving the city of Lisburn and Castlereagh
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
(recommended)
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: lisburn_castlereagh_gov_uk
|
||||
args:
|
||||
property_id: "PROPERTY_ID"
|
||||
```
|
||||
|
||||
or (not recommended)
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: lisburn_castlereagh_gov_uk
|
||||
args:
|
||||
post_code: "BT28 1AG"
|
||||
house_number: "19A"
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**property_id**
|
||||
*(string) (required if post_code not provided)*
|
||||
|
||||
**post_code**
|
||||
*(string) (required if property_id not provided)*
|
||||
|
||||
**house_number**
|
||||
*(string) (required if property_id not provided)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: lisburn_castlereagh_gov_uk
|
||||
args:
|
||||
property_id: "DYYSm8Ls8XxGi3Nq"
|
||||
```
|
||||
|
||||
## How to get the property_id argument
|
||||
|
||||
The property_id can be found in the URL when looking up your
|
||||
bin collection days at [Lisburn and Castlereagh bin collection days](https://lisburn.isl-fusion.com).
|
||||
|
||||
## Why property_id over post_code and house_number?
|
||||
|
||||
The code has to do a search by post code and house number then look up the bin collection time using property ID
|
||||
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 | Affärsverken, 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, Uppsala Vatten och Avfall AB, 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, Basildon Council, Basingstoke and Deane Borough Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, 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 Bexley, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, 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, Portsmouth City Council, Reading Council, Reigate & Banstead Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wyre Forest District Council |
|
||||
| United Kingdom | Amber Valley Borough Council, Ashfield District Council, Basildon Council, Basingstoke and Deane Borough Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, 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, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, 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, Portsmouth City Council, Reading Council, Reigate & Banstead Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wyre Forest District Council |
|
||||
| United States of America | City of Oklahoma City, City of Pittsburgh, Republic Services, Seattle Public Utilities |
|
||||
<!--End of country section-->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user