mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
refactor stockport_gov_uk
This commit is contained in:
@@ -390,6 +390,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [South Norfolk and Broadland Council](/doc/source/south_norfolk_and_broadland_gov_uk.md) / area.southnorfolkandbroadland.gov.uk
|
||||
- [Southampton City Council](/doc/source/southampton_gov_uk.md) / southampton.gov.uk
|
||||
- [Stevenage Borough Council](/doc/source/stevenage_gov_uk.md) / stevenage.gov.uk
|
||||
- [Stockport Council](/doc/source/stockport_gov_uk.md) / stockport.gov.uk
|
||||
- [Telford and Wrekin Council](/doc/source/telford_gov_uk.md) / telford.gov.uk
|
||||
- [Tewkesbury Borough Council](/doc/source/tewkesbury_gov_uk.md) / tewkesbury.gov.uk
|
||||
- [The Royal Borough of Kingston Council](/doc/source/kingston_gov_uk.md) / kingston.gov.uk
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
import logging
|
||||
|
||||
TITLE = "stockport.gov.uk"
|
||||
TITLE = "Stockport Council"
|
||||
DESCRIPTION = "Source for bin collection services for Stockport Council, UK.\n Refactored with thanks from the Manchester equivalent"
|
||||
URL = "https://myaccount.stockport.gov.uk/bin-collections/show/"
|
||||
URL = "https://stockport.gov.uk"
|
||||
TEST_CASES = {
|
||||
"domestic": {'uprn': '100011460157'},
|
||||
"domestic": {"uprn": "100011460157"},
|
||||
}
|
||||
|
||||
ICONS = {
|
||||
ICON_MAP = {
|
||||
"Black bin": "mdi:trash-can",
|
||||
"Blue bin": "mdi:recycle",
|
||||
"Brown bin": "mdi:glass-fragile",
|
||||
@@ -26,49 +24,42 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(
|
||||
self, uprn: int = None
|
||||
):
|
||||
def __init__(self, uprn):
|
||||
self._uprn = uprn
|
||||
if not self._uprn:
|
||||
_LOGGER.error(
|
||||
"uprn must be provided in config"
|
||||
)
|
||||
self._session = requests.Session()
|
||||
|
||||
def fetch(self):
|
||||
entries = []
|
||||
|
||||
bin_URL = URL + self._uprn
|
||||
|
||||
r = requests.get(
|
||||
bin_URL,
|
||||
)
|
||||
f"https://myaccount.stockport.gov.uk/bin-collections/show/{self._uprn}"
|
||||
)
|
||||
|
||||
soup = BeautifulSoup(r.text, features="html.parser")
|
||||
|
||||
results = soup.find_all("div", {"class": "collection"})
|
||||
bins = soup.find_all("div" ,{"class": re.compile("service-item service-item-.*")})
|
||||
bins = soup.find_all(
|
||||
"div", {"class": re.compile("service-item service-item-.*")}
|
||||
)
|
||||
|
||||
bins = str(bins)
|
||||
header_string = "<h3>"
|
||||
bin_name_start_position = bins.find(header_string)
|
||||
|
||||
entries = []
|
||||
while bin_name_start_position != -1:
|
||||
bin_name_start_position += len(header_string)
|
||||
bin_name_end_position = bins.find(" bin",bin_name_start_position) + 4
|
||||
bin_name_end_position = bins.find(" bin", bin_name_start_position) + 4
|
||||
bin_name = bins[bin_name_start_position:bin_name_end_position]
|
||||
bin_date_pos = bins.find("<p>",bin_name_start_position)
|
||||
bin_date_exc_day_of_week_pos = bins.find(", ",bin_date_pos)+2
|
||||
bin_date_end_pos = bins.find("</p>",bin_date_exc_day_of_week_pos)
|
||||
bin_date_pos = bins.find("<p>", bin_name_start_position)
|
||||
bin_date_exc_day_of_week_pos = bins.find(", ", bin_date_pos) + 2
|
||||
bin_date_end_pos = bins.find("</p>", bin_date_exc_day_of_week_pos)
|
||||
bin_date_string = bins[bin_date_exc_day_of_week_pos:bin_date_end_pos]
|
||||
bin_date = datetime.strptime(bin_date_string,'%d %B %Y').date()
|
||||
bin_date = datetime.strptime(bin_date_string, "%d %B %Y").date()
|
||||
entries.append(
|
||||
Collection(
|
||||
date=bin_date,
|
||||
t=bin_name,
|
||||
icon=ICONS[bin_name],
|
||||
icon=ICON_MAP.get(bin_name),
|
||||
)
|
||||
)
|
||||
bin_name_start_position = bins.find(header_string,bin_date_end_pos)
|
||||
bin_name_start_position = bins.find(header_string, bin_date_end_pos)
|
||||
|
||||
return entries
|
||||
|
||||
2
info.md
2
info.md
@@ -28,7 +28,7 @@ Waste collection schedules from service provider web sites are updated daily, de
|
||||
| Poland | Ecoharmonogram, Warsaw |
|
||||
| Sweden | Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Ronneby Miljöteknik, SRV Återvinning, SSAM, Sysav Sophämntning, 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 | Ashfield District Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Harlow Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Somerset Council, Nottingham City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council |
|
||||
| United Kingdom | Ashfield District Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Harlow Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Somerset Council, Nottingham City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council |
|
||||
| United States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |
|
||||
<!--End of country section-->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user