mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 00:04:11 +01:00
Add source for fareham.gov.uk (#914)
* Add source for fareham.gov.uk * minor md reformatting
This commit is contained in:
@@ -667,6 +667,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Eastbourne Borough Council](/doc/source/environmentfirst_co_uk.md) / lewes-eastbourne.gov.uk
|
||||
- [Elmbridge Borough Council](/doc/source/elmbridge_gov_uk.md) / elmbridge.gov.uk
|
||||
- [Environment First](/doc/source/environmentfirst_co_uk.md) / environmentfirst.co.uk
|
||||
- [Fareham Council](/doc/source/fareham_gov_uk.md) / fareham.gov.uk
|
||||
- [FCC Environment](/doc/source/fccenvironment_co_uk.md) / fccenvironment.co.uk
|
||||
- [Fenland District Council](/doc/source/fenland_gov_uk.md) / fenland.gov.uk
|
||||
- [Fife Council](/doc/source/fife_gov_uk.md) / fife.gov.uk
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
from datetime import date
|
||||
import re
|
||||
from dateutil.parser import parse as date_parse
|
||||
from waste_collection_schedule import Collection
|
||||
import requests
|
||||
|
||||
TITLE = "Fareham Council"
|
||||
DESCRIPTION = "Source for fareham.gov.uk"
|
||||
URL = "https://www.fareham.gov.uk"
|
||||
TEST_CASES = {
|
||||
"HUNTS_POND_ROAD": {"road_name": "Hunts pond road", "postcode": "PO14 4PL"},
|
||||
"CHRUCH_ROAD": {"road_name": "Church road", "postcode": "SO31 6LW"},
|
||||
"BRIDGE_ROAD": {"road_name": "Bridge road", "postcode": "SO31 7GD"},
|
||||
}
|
||||
|
||||
API_URL = "https://www.fareham.gov.uk/internetlookups/search_data.aspx"
|
||||
ICON_MAP = {
|
||||
"Refuse": "mdi:trash-can",
|
||||
"Recycling": "mdi:recycle",
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, road_name, postcode):
|
||||
self._road_name = road_name
|
||||
self._postcode = postcode
|
||||
|
||||
def fetch(self):
|
||||
entries = []
|
||||
params = {
|
||||
"type": "JSON",
|
||||
"list": "DomesticBinCollections",
|
||||
"Road": self._road_name,
|
||||
"Postcode": self._postcode,
|
||||
}
|
||||
headers = {
|
||||
"user-agent": "Mozilla/5.0",
|
||||
}
|
||||
response = requests.get(API_URL, params=params, headers=headers, timeout=30)
|
||||
# Some queries (Bridge Road test case) return duplicate results, we only want to process
|
||||
# unique bin collection dates
|
||||
unique_entries = set(
|
||||
map(lambda row: row["DomesticBinDay"], response.json()["data"]["rows"])
|
||||
)
|
||||
|
||||
for entry in unique_entries:
|
||||
for collection in self.extract_collections(entry):
|
||||
entries.append(collection)
|
||||
|
||||
return entries
|
||||
|
||||
def extract_collections(self, string):
|
||||
"""
|
||||
Given a string in the forms:
|
||||
"Thursday - Collections are 20/04/2023 (Refuse) and 27/04/2023 (Recycling)"
|
||||
"Thursday - Collections are today (Refuse) and 27/04/2023 (Recycling)"
|
||||
|
||||
It will extract the dates and waste_types to create Collection objects
|
||||
"""
|
||||
collections = []
|
||||
for match in re.finditer(
|
||||
r"(?P<date>\d{1,2}\/\d{1,2}\/\d{4}|today) \((?P<waste_type>\w+)\)", string
|
||||
):
|
||||
if match.group("date") == "today":
|
||||
collection_date = date.today()
|
||||
else:
|
||||
collection_date = date_parse(match.group("date"), dayfirst=True).date()
|
||||
|
||||
waste_type = match.group("waste_type")
|
||||
collections.append(
|
||||
Collection(
|
||||
date=collection_date,
|
||||
t=waste_type,
|
||||
icon=ICON_MAP[waste_type],
|
||||
)
|
||||
)
|
||||
return collections
|
||||
@@ -74,7 +74,7 @@ Filtering of data for waste types or time periods is a functionality of the fram
|
||||
|
||||
## Service Provider Markdown File
|
||||
|
||||
Create a new markdown file in the `custom_components/waste_collection_schedule/doc/source` folder. The file name should be the url of your service provider in lower case, for example `abc_com.md` for `https://www.abc.com`.
|
||||
Create a new markdown file in the `doc/source` folder. The file name should be the url of your service provider in lower case, for example `abc_com.md` for `https://www.abc.com`.
|
||||
|
||||
The markdown file should have the following general structure:
|
||||
|
||||
|
||||
37
doc/source/fareham_gov_uk.md
Normal file
37
doc/source/fareham_gov_uk.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Fareham Council
|
||||
|
||||
The fareham gov uk website does not return all future collection dates, only the next upcoming one. You can test different addresses at <https://www.fareham.gov.uk/internetlookups/search.aspx?list=DomesticBinCollections>.
|
||||
|
||||
Credit to Fareham Borough Council for all data fetched from their API.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: fareham_gov_uk
|
||||
args:
|
||||
road_name: Road name
|
||||
postcode: Post code
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**road_name**
|
||||
_(string) (required)_
|
||||
The name of the road the house is on
|
||||
|
||||
**postcode**
|
||||
_(string) (required)_
|
||||
The post code for the house
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: fareham_gov_uk
|
||||
args:
|
||||
road_name: Hunts pond road
|
||||
postcode: PO14 4PL
|
||||
```
|
||||
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, 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, 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, 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 Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District 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, 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, 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 Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District 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