diff --git a/README.md b/README.md index d36dbf55..3e9ce05a 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ Currently the following service providers are supported: - [Peterborough City Council - peterborough.gov.uk](./doc/source/peterborough_gov_uk.md) - [South Cambridgeshire District Council - scambs.gov.uk](./doc/source/scambs_gov_uk.md) - [City of York Council - york.gov.uk](./doc/source/york_gov_uk.md) +- [Wiltshire Council - wiltshire.gov.uk](./doc/source/wiltshire_gov_uk.md) ## Installation diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/wiltshire_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/wiltshire_gov_uk.py new file mode 100755 index 00000000..6364be0b --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/wiltshire_gov_uk.py @@ -0,0 +1,50 @@ +import requests + +from datetime import datetime +from bs4 import BeautifulSoup +from waste_collection_schedule import Collection + +TITLE = "Wiltshire Council, UK" +DESCRIPTION = "Source for wiltshire.gov.uk services for Wiltshire Council" +URL = "wiltshire.gov.uk" +TEST_CASES = { + "house_uprn": {"uprn": "100121085972", "postcode": "BA149QP"}, +} +SEARCH_URLS = { + "collection_search": "https://ilforms.wiltshire.gov.uk/wastecollectiondays/collectionlist" +} +COLLECTIONS = {"Household waste", + "Mixed dry recycling (blue lidded bin) and glass (black box or basket)"} + + +class Source: + def __init__( + self, uprn=None, postcode=None, housenumberorname=None + ): # argX correspond to the args dict in the source configuration + self._uprn = uprn + self._postcode = postcode + + def fetch(self): + entries = [] + session = requests.Session() + args = { + "Postcode": self._postcode, + "Uprn": self._uprn, + } + r = session.post(SEARCH_URLS["collection_search"], params=args) + r.raise_for_status() + soup = BeautifulSoup(r.text, 'html.parser') + for collection in COLLECTIONS: + for tag in soup.find_all( + attrs={"data-original-title": collection} + ): + + entries.append( + Collection( + datetime.strptime( + tag['data-original-datetext'], "%A %d %B, %Y").date(), + collection, + ) + ) + + return entries diff --git a/doc/source/wiltshire_gov_uk.md b/doc/source/wiltshire_gov_uk.md new file mode 100644 index 00000000..17498c84 --- /dev/null +++ b/doc/source/wiltshire_gov_uk.md @@ -0,0 +1 @@ +TODO: \ No newline at end of file diff --git a/info.md b/info.md index 51acb533..f55f876d 100644 --- a/info.md +++ b/info.md @@ -147,3 +147,4 @@ Currently the following service providers are supported: - [Peterborough City Council - peterborough.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/peterborough_gov_uk.md) - [South Cambridgeshire District Council - scambs.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/scambs_gov_uk.md) - [City of York Council - york.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/york_gov_uk.md) +- [Wiltshire Council - wiltshire.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/wiltshire_gov_uk.md) \ No newline at end of file