Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nvaa_se source #2214

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Waldshut](/doc/source/app_abfallplus_de.md) / Abfall+ App: unterallgaeu
- [WBO Wirtschaftsbetriebe Oberhausen](/doc/source/abfallnavi_de.md) / wbo-online.de
- [Wegberg (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
- [Wermelskirchen](/doc/source/wermelskirchen_de.md) / wermelskirchen.de
- [Wermelskirchen (Service Down)](/doc/source/wermelskirchen_de.md) / wermelskirchen.de
5ila5 marked this conversation as resolved.
Show resolved Hide resolved
- [Westerholt (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
- [Westerwaldkreis](/doc/source/app_abfallplus_de.md) / Abfall+ App: wabapp
- [WGV Recycling GmbH](/doc/source/awido_de.md) / wgv-quarzbichl.de
Expand Down Expand Up @@ -1133,6 +1133,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Lerum Vatten och Avlopp](/doc/source/lerum_se.md) / vatjanst.lerum.se
- [Linköping - Tekniska Verken](/doc/source/tekniskaverken_se.md) / tekniskaverken.se
- [Lund Waste Collection](/doc/source/lund_se.md) / eservice431601.lund.se
- [Norrtalje Vatten & Avfall](/doc/source/nvaa_se.md) / sjalvservice.nvaa.se
- [North / Middle Bohuslän - Rambo AB](/doc/source/rambo_se.md) / rambo.se
- [Region Gotland](/doc/source/gotland_se.md) / gotland.se
- [Ronneby Miljöteknik](/doc/source/miljoteknik_se.md) / fyrfackronneby.se
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from datetime import datetime

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Norrtalje Vatten & Avfall"
DESCRIPTION = "Source for Norrtalje Vatten & Avfall waste collection services, Sweden."
URL = "https://sjalvservice.nvaa.se/"

API_URL = f"{URL}api/v1/integration/"

NEXT_COLLECTION_URL = f"{API_URL}getNextGarbageCollection"
FIND_ADDRESS_URL = f"{API_URL}findAddress"


TEST_CASES = {
"Gustav Adolfs väg 24, Norrtälje": {
"street_address": "Gustav Adolfs väg 24, Norrtälje"
},
}


ICON_MAP = {
"Restavfall": "mdi:trash-can",
"Matavfall": "mdi:food-apple",
"Slam": "mdi:valve",
}


def parse_date(next_pickup_date):
"""Parse the date string into a datetime object.

There are two possible date formats: specific days in Swedish and weeks
Specific date: Tisdag 4 juni 2024
week: v10 2025
"""
if next_pickup_date.startswith("v"):
# Parse week format
week_number = int(next_pickup_date[1:].split()[0])
year = int(next_pickup_date.split()[1])
date_obj = datetime.strptime(f"{year}-W{week_number - 1}-1", "%Y-W%W-%w").date()
else:
# Parse specific date format
swedish_days = {
"Måndag": "Monday",
"Tisdag": "Tuesday",
"Onsdag": "Wednesday",
"Torsdag": "Thursday",
"Fredag": "Friday",
"Lördag": "Saturday",
"Söndag": "Sunday",
}
swedish_months = {
"januari": 1,
"februari": 2,
"mars": 3,
"april": 4,
"maj": 5,
"juni": 6,
"juli": 7,
"augusti": 8,
"september": 9,
"oktober": 10,
"november": 11,
"december": 12,
}
day, day_number, month, year = next_pickup_date.split()
day = swedish_days[day]
month = swedish_months[month]
date_obj = datetime.strptime(f"{year}-{month}-{day_number}", "%Y-%m-%d").date()

return date_obj


class Source:
def __init__(self, street_address):
self.street_address = street_address

def fetch_building_id(self, session):
search_payload = {"address": self.street_address}
response = session.post(
FIND_ADDRESS_URL,
data=search_payload,
)
search_data = response.json()["results"]

if len(search_data) == 0:
raise ValueError(f"Search for address failed for {self.street_address}.")

building_id = search_data[0].get("id")
if not building_id:
raise ValueError(f"Failed to get address ID for {self.street_address}.")

return building_id

def fetch_schedule_for_building_id(self, session, building_id):
data = {"buildingId": building_id}

response = session.post(NEXT_COLLECTION_URL, json=data)
schedule_data = response.json()

return schedule_data

def format_schedule_data(self, schedule_data):
entries = []
for service in schedule_data:
waste_type = service["product"]
next_pickup_date = service["next_collection"]
date_obj = parse_date(next_pickup_date)
entries.append(
Collection(date=date_obj, t=waste_type, icon=ICON_MAP.get(waste_type))
)
return entries

def fetch(self):
with requests.Session() as s:
building_id = self.fetch_building_id(s)
schedule_data = self.fetch_schedule_for_building_id(s, building_id)

entries = self.format_schedule_data(schedule_data)

return entries
29 changes: 29 additions & 0 deletions doc/source/nvaa_se.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# NVAA (Norrtälje Vatten och Avfall)

Support for schedules provided by [NVAA](https://www.nvaa.se), Sweden.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: nvaa_se
args:
street_address: STREET ADDRESS

```

### Configuration Variables

**street_address**
*(string) (required)*

## Example

```yaml
waste_collection_schedule:
sources:
- name: nvaa_se
args:
streetAddress: "Gustav Adolfs väg 24"
```
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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, Gmina Miękinia, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław |
| Slovenia | Moji odpadki, Ljubljana |
| 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, VIVAB Sophämtning |
| 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, Norrtalje Vatten & Avfall, 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, VIVAB Sophämtning |
| Switzerland | A-Region, Alchenstorf, Andwil, Appenzell, Berg, Bühler, Canton of Zürich, 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, Barnsley Metropolitan Borough Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, BCP Council, Bedford Borough Council, Binzone, Birmingham City Council, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, Borough of Broxbourne Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Bromsgrove City Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Bury 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, Denbighshire County Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Ayrshire Council, East Cambridgeshire District Council, East Devon District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Eastleigh Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Flintshire, Fylde 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 Barking and Dagenham, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Harrow, London Borough of Hounslow, London Borough of Lewisham, London Borough of Merton, London Borough of Newham, 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 Ayrshire Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Northamptonshire council, North Somerset Council, North West Leicestershire District Council, North Yorkshire Council - Hambleton, North Yorkshire Council - Harrogate, North Yorkshire Council - Scarborough, North Yorkshire Council - Selby, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Renfrewshire 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, Shropshire 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, Stafford Borough Council, Stevenage Borough Council, Stirling.gov.uk, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Sutton Council, London, 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, Tunbridge Wells, 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 Northamptonshire council, West Suffolk Council, Westmorland & Furness Council, Barrow area, Westmorland & Furness Council, South Lakeland area, 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 Austin, TX, 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 |
Expand Down
Loading