Added source Gästrike Återvinnare (#1667)

* Added source Gastrike Återvinnare

* reformat + raise exception instead of returning [] + fixed typo

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
Emil Torp
2024-01-15 23:32:13 +01:00
committed by GitHub
parent 3dd16e6b04
commit 3123b83dac
4 changed files with 116 additions and 1 deletions

View File

@@ -1075,6 +1075,7 @@ Waste collection schedules in the following formats and countries are supported.
<summary>Sweden</summary>
- [Affärsverken](/doc/source/affarsverken_se.md) / affarsverken.se
- [Gästrike Återvinnare](/doc/source/gastrikeatervinnare_se.md) / gastrikeatervinnare.se
- [Jönköping - June Avfall & Miljö](/doc/source/juneavfall_se.md) / juneavfall.se
- [Landskrona - Svalövs Renhållning](/doc/source/lsr_nu.md) / lsr.nu
- [Lerum Vatten och Avlopp](/doc/source/lerum_se.md) / vatjanst.lerum.se

View File

@@ -0,0 +1,75 @@
from datetime import date
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Gästrike Återvinnare"
DESCRIPTION = "Source for Gästrike Återvinnare waste collection"
URL = "https://gastrikeatervinnare.se/"
API_URL = "https://gastrikeatervinnare.se/wp-admin/admin-ajax.php"
TEST_CASES = {
"Groceries Årsunda": {"street": "Nedre Vägen 52", "city": "Årsunda"},
"Police Sandviken": {"street": "Bryggargatan 6", "city": "Sandviken"},
"Police Gävle": {"street": "Södra Centralgatan 1", "city": "Gävle"},
"Library Ockelbo": {"street": "Södra Åsgatan 30D", "city": "Ockelbo"},
}
ICON_MAP = {
"Restavfall": "mdi:trash-can",
"Matavfall": "mdi:leaf",
"Blandat": "mdi:trash-can",
}
class Source:
def __init__(self, street, city):
self._street = street.strip().lower()
self._city = city.strip().lower()
def fetch(self):
data = {"action": "pickup_search", "query": self._street}
response = requests.post(API_URL, data=data)
response.encoding = "UTF-8"
soup = BeautifulSoup(response.text, "html.parser")
addresses = soup.find_all("p", attrs={"class": "pickup-adress"})
infos = soup.find_all("div", attrs={"class": "pickup-types"})
for addressTag, info in zip(addresses, infos):
street = addressTag.text.split(",")[0].strip().lower()
city = (
addressTag.find("span", attrs={"class": "pickup-locality"})
.text.strip()
.lower()
)
if street == self._street and city == self._city:
return self.get_entries(info)
raise Exception("Address not found")
def get_entries(self, info):
entries = []
waste_types_info = info.find_all("div", attrs={"class": "pickup-row"})
for waste_type_info in waste_types_info:
waste_type = waste_type_info["class"][1].capitalize()
pickup_date = self.get_date(waste_type_info)
icon = ICON_MAP.get(waste_type)
entries.append(Collection(date=pickup_date, t=waste_type, icon=icon))
return entries
def get_date(self, waste_type_info):
pickup_date = (
waste_type_info.find("div", attrs={"class": "pickup-time"})
.find_all("span")[1]
.text.split(" ")[1]
)
today = date.today()
pickup_date_day = int(pickup_date.split("/")[0])
pickup_date_month = int(pickup_date.split("/")[1])
pickup_date_year = today.year
if pickup_date_month < today.month:
pickup_date_year = pickup_date_year + 1
return date(pickup_date_year, pickup_date_month, int(pickup_date_day))

View File

@@ -0,0 +1,39 @@
# Gästrike Återvinnare
Support for schedules provided by [Gästrike Återvinnare](https://gastrikeatervinnare.se/privat/hamtningsdag/), serving the region of Gästrikland, Sweden.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: gastrikeatervinnare_se
args:
street: STREET_NAME
city: CITY_NAME
```
### Configuration Variables
**street**
*(string) (required)*
**city**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: tekniskaverken_se
args:
street: Bryggargatan 6
city: Sandviken
```
## How to get the source argument
The source argument is the street including number and the city to the house with waste collection.
The address can be tested [here](https://gastrikeatervinnare.se/privat/hamtningsdag/).
Note that the city can't be used in the search above, and is only used as a differentiator in case several citys have the same street address.

View File

@@ -32,7 +32,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Norway | BIR (Bergensområdets Interkommunale Renovasjonsselskap), IRiS, Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Sandnes Kommune, Stavanger Kommune, Trondheim |
| Poland | Ecoharmonogram, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław |
| Slovenia | Moji odpadki, Ljubljana |
| Sweden | Affärsverken, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Lund Waste Collection, North / Middle Bohuslän - Rambo AB, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning |
| Sweden | Affärsverken, Gästrike Återvinnare, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Lund Waste Collection, North / Middle Bohuslän - Rambo AB, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning |
| Switzerland | A-Region, Alchenstorf, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Münsingen BE, Switzerland, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
| United Kingdom | Aberdeenshire Council, Adur & Worthing Councils, Allerdale Borough Council, Amber Valley Borough Council, Anglesey, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Cheshire West and Chester Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City Of Lincoln Council, City of York Council, Colchester City Council, Conwy County Borough Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Haringey Council, Harlow Council, Hart District Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Lancaster City Council, Leicester City Council, Lewes District Council, Lichfield District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Harrow, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mansfield District Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Moray Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, North Yorkshire Council - Hambleton, North Yorkshire Council - Harrogate, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swansea Council, Swindon Borough Council, Tameside Metropolitan Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, UK Bin Collection Schedule (UKBCD) project, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Warwick District Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, West Suffolk Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wokingham Borough Council, Wyre Forest District Council |
| United States of America | Albuquerque, New Mexico, USA, City of Bloomington, City of Cambridge, City of Gastonia, NC, City of Georgetown, TX, City of Oklahoma City, City of Pittsburgh, Louisville, Kentucky, USA, Newark, Delaware, USA, Olympia, Washington, USA, ReCollect, Recycle Coach, Republic Services, Seattle Public Utilities, Tucson, Arizona, USA |