add wiltshire council source

This commit is contained in:
Russell Hall
2022-07-17 18:54:07 +01:00
parent c9805b29b3
commit a7bac70f8a
4 changed files with 53 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1 @@
TODO:

View File

@@ -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)