mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
adding glasgow_gov_uk
This commit is contained in:
@@ -366,6 +366,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Elmbridge Borough Council](/doc/source/elmbridge_gov_uk.md) / elmbridge.gov.uk
|
||||
- [Environment First](/doc/source/environmentfirst_co_uk.md) / environmentfirst.co.uk
|
||||
- [FCC Environment](/doc/source/fccenvironment_co_uk.md) / fccenvironment.co.uk
|
||||
- [Glasgow City Council](/doc/source/glasgow_gov_uk.md) / glasgow.gov.uk
|
||||
- [Guildford Borough Council](/doc/source/guildford_gov_uk.md) / guildford.gov.uk
|
||||
- [Harborough District Council](/doc/source/fccenvironment_co_uk.md) / harborough.gov.uk
|
||||
- [Harlow Council](/doc/source/harlow_gov_uk.md) / harlow.gov.uk
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
import re
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
TITLE = "Glasgow City Council"
|
||||
DESCRIPTION = (
|
||||
"Source for www.glasgow.gov.uk services for Glasgow City Council, UK."
|
||||
)
|
||||
URL = "https://www.glasgow.gov.uk/"
|
||||
TEST_CASES = {
|
||||
"test 1 - house": {"uprn": "906700099060"},
|
||||
"test 2 - flat": {"uprn": "906700335412"}
|
||||
}
|
||||
|
||||
API_URL = "https://www.glasgow.gov.uk/forms/refuseandrecyclingcalendar/CollectionsCalendar.aspx?UPRN="
|
||||
ICON_MAP = {
|
||||
"purple bins": "mdi:glass-fragile",
|
||||
"brown bins": "mdi:apple",
|
||||
"green bins": "mdi:trash-can",
|
||||
"blue bins": "mdi:recycle",
|
||||
"GREY bins": "mdi:apple",
|
||||
}
|
||||
|
||||
from pprint import pprint
|
||||
|
||||
class Source:
|
||||
def __init__(self, uprn: str):
|
||||
self._uprn = uprn
|
||||
|
||||
def __parseBins(self, soup):
|
||||
entries = []
|
||||
|
||||
days = soup.find_all("td", {"class": "CalendarDayStyle"})
|
||||
for day in days:
|
||||
bins = day.find_all("img")
|
||||
|
||||
if len(bins) < 1:
|
||||
continue
|
||||
|
||||
date = datetime.strptime(day["title"].replace("today is ",""), "%A, %d %B %Y").date()
|
||||
|
||||
for bin in bins:
|
||||
binname = bin["title"].split()
|
||||
binname = f"{binname[0]} {binname[1]}"
|
||||
entries.append(
|
||||
Collection(
|
||||
date=date,
|
||||
t=binname,
|
||||
icon=ICON_MAP.get(binname),
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
|
||||
def fetch(self):
|
||||
if self._uprn is None:
|
||||
raise Exception("No uprn supplied")
|
||||
entries = []
|
||||
|
||||
session = requests.Session()
|
||||
|
||||
# get current month
|
||||
r = session.get(f"{API_URL}{self._uprn}")
|
||||
soup = BeautifulSoup(r.text, features="html.parser")
|
||||
entries = entries + self.__parseBins(soup)
|
||||
|
||||
# get next month otherwise at end of month you will have no future collection dates
|
||||
nextlink = soup.find("a", title="Go to the next month")
|
||||
if len(nextlink) > 0:
|
||||
match = re.search(r"__doPostBack\('(.*?)','(.*?)'", nextlink["href"])
|
||||
eventtarget = match.group(1)
|
||||
eventargument = match.group(2)
|
||||
eventvalidation = soup.find("input", id="__EVENTVALIDATION")["value"]
|
||||
viewstate = soup.find("input", id="__VIEWSTATE")["value"]
|
||||
data = {
|
||||
"__EVENTTARGET": eventtarget,
|
||||
"__EVENTARGUMENT": eventargument,
|
||||
"__EVENTVALIDATION": eventvalidation,
|
||||
"__VIEWSTATE": viewstate
|
||||
}
|
||||
r =session.post(f"{API_URL}{self._uprn}", data=data)
|
||||
|
||||
soup = BeautifulSoup(r.text, features="html.parser")
|
||||
entries = entries + self.__parseBins(soup)
|
||||
|
||||
return entries
|
||||
35
doc/source/glasgow_gov_uk.md
Normal file
35
doc/source/glasgow_gov_uk.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Glasgow City Council
|
||||
|
||||
Support for schedules provided by [Glasgow City Council](https://www.glasgow.gov.uk/forms/refuseandrecyclingcalendar/AddressSearch.aspx), serving the
|
||||
city of Glasgow, UK.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: glasgow_gov_uk
|
||||
args:
|
||||
uprn: UPRN_CODE
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**uprn**
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: glasgow_gov_uk
|
||||
args:
|
||||
uprn: "906700099060"
|
||||
```
|
||||
|
||||
## How to get the uprn argument above
|
||||
|
||||
The UPRN code can be found by entering your postcode or address on the
|
||||
[Glasgow City Council Bin Collections page
|
||||
](https://www.glasgow.gov.uk/forms/refuseandrecyclingcalendar/AddressSearch.aspx). When on the address list click the 'select' link for your address then on the calendar page look in the browser address bar for your UPRN code e.g. https://www.glasgow.gov.uk/forms/refuseandrecyclingcalendar/CollectionsCalendar.aspx?UPRN=YOURUPRNSHOWNHERE.
|
||||
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, 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 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, Glasgow City Council, 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