mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
add wiltshire council source
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
1
doc/source/wiltshire_gov_uk.md
Normal file
1
doc/source/wiltshire_gov_uk.md
Normal file
@@ -0,0 +1 @@
|
||||
TODO:
|
||||
1
info.md
1
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)
|
||||
Reference in New Issue
Block a user