Skip to content

Commit

Permalink
New Source: Allerdale, UK (mampfes#1222)
Browse files Browse the repository at this point in the history
* allerdale adapted from eastherts

* allerdale .md added

* update_docu_links run

* fix typo
  • Loading branch information
dt215git authored Sep 2, 2023
1 parent 738845e commit 14cd06c
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ Waste collection schedules in the following formats and countries are supported.
<summary>United Kingdom</summary>

- [Aberdeenshire Council](/doc/source/aberdeenshire_gov_uk.md) / aberdeenshire.gov.uk
- [Allerdale Borough Council](/doc/source/allerdale_gov_uk.md) / allerdale.gov.uk
- [Amber Valley Borough Council](/doc/source/ambervalley_gov_uk.md) / ambervalley.gov.uk
- [Ashfield District Council](/doc/source/ashfield_gov_uk.md) / ashfield.gov.uk
- [Ashford Borough Council](/doc/source/ashford_gov_uk.md) / ashford.gov.uk
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import logging
from datetime import datetime

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

TITLE = "Allerdale Borough Council"
DESCRIPTION = "Source for www.allerdale.gov.uk services for Allerdale Borough Council."
URL = "https://www.allerdale.gov.uk"
TEST_CASES = {
"Keswick": {
"address_postcode": "CA12 4HU",
"address_name_number": "11",
},
"Workington": {
"address_postcode": "CA14 3NS",
"address_name_number": "177",
},
"Wigton": {
"address_postcode": "CA7 9RS",
"address_name_number": "55",
},
}
ICON_MAP = {
"Domestic Waste": "mdi:trash-can",
"Glass Cans and Plastic Recycling": "mdi:recycle",
"Garden Waste": "mdi:leaf",
}
API_URL = "https://abc-wrp.whitespacews.com/"

_LOGGER = logging.getLogger(__name__)


class Source:
def __init__(
self,
address_name_number=None,
address_postcode=None,
):
self._address_name_number = address_name_number
self._address_postcode = address_postcode

def fetch(self):
session = requests.Session()

# get link from first page as has some kind of unique hash
r = session.get(
API_URL,
)
r.raise_for_status()
soup = BeautifulSoup(r.text, features="html.parser")

alink = soup.find("a", text="View My Collections")

if alink is None:
raise Exception("Initial page did not load correctly")

# replace 'seq' query string to skip next step
nextpageurl = alink["href"].replace("seq=1", "seq=2")

data = {
"address_name_number": self._address_name_number,
"address_postcode": self._address_postcode,
}

# get list of addresses
r = session.post(nextpageurl, data)
r.raise_for_status()

soup = BeautifulSoup(r.text, features="html.parser")

# get first address (if you don't enter enough argument values this won't find the right address)
alink = soup.find("div", id="property_list").find("a")

if alink is None:
raise Exception("Address not found")

nextpageurl = API_URL + alink["href"]

# get collection page
r = session.get(
nextpageurl,
)
r.raise_for_status()
soup = BeautifulSoup(r.text, features="html.parser")

if soup.find("span", id="waste-hint"):
raise Exception("No scheduled services at this address")

u1s = soup.find("section", id="scheduled-collections").find_all("u1")

entries = []

for u1 in u1s:
lis = u1.find_all("li", recursive=False)
entries.append(
Collection(
date=datetime.strptime(
lis[1].text.replace("\n", ""), "%d/%m/%Y"
).date(),
t=lis[2].text.replace("\n", ""),
icon=ICON_MAP.get(
lis[2]
.text.replace("\n", "")
.replace(" Collection", "")
.replace(" Service", "")
),
)
)

return entries
36 changes: 36 additions & 0 deletions doc/source/allerdale_gov_uk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Allerdale Borough Council

Support for schedules provided by [Allerdale Borough Council](https://www.allerdale.gov.uk/en/waste-recycling/), serving the Allerdale district, UK.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: allerdale_gov_uk
args:
address_postcode: POST_CODE
address_name_number: HOUSE_NAME_NUMBER
```
### Configuration Variables
If you have a house name, or both a house name and house number, determine which is best to use manually at [Allerdale Borough Council](https://www.allerdale.gov.uk/en/waste-recycling/).
**ADDRESS_POSTCODE**
*(string) (required)*
**ADDRESS_NAME_NUMBER**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: allerdale_gov_uk
args:
address_postcode: "CA12 4HU"
address_name_number: "11"
```
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff 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, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees 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 Camden, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, North Yorkshire Council - Hambleton, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough 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, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wyre Forest District Council |
| United Kingdom | Aberdeenshire Council, Allerdale Borough Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff 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, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees 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 Camden, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, North Yorkshire Council - Hambleton, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough 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, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wyre Forest District Council |
| United States of America | Albuquerque, New Mexico, USA, City of Bloomington, City of Cambridge, City of Gastonia, NC, City of Georgetown, TX, City of Oklahoma City, City of Pittsburgh, Louisville, Kentucky, USA, Newark, Delaware, USA, Olympia, Washington, USA, ReCollect, Recycle Coach, Republic Services, Seattle Public Utilities, Tucson, Arizona, USA |
<!--End of country section-->

Expand Down

0 comments on commit 14cd06c

Please sign in to comment.