Add mojiodpadki.si, Ljubljana, Slovenia source

This commit is contained in:
Andrej Komelj
2023-02-01 12:03:54 +01:00
parent 20ff3467f5
commit d86d3f39bc
5 changed files with 159 additions and 2 deletions

View File

@@ -286,6 +286,12 @@ Waste collection schedules in the following formats and countries are supported.
- [Warsaw](/doc/source/warszawa19115_pl.md) / warszawa19115.pl
</details>
<details>
<summary>Slovenia</summary>
- [Moji odpadki, Ljubljana](/doc/source/mojiodpadki_si.md) / mojiodpadki.si
</details>
<details>
<summary>Sweden</summary>
@@ -393,8 +399,8 @@ Waste collection schedules in the following formats and countries are supported.
- [Rushmoor Borough Council](/doc/source/rushmoor_gov_uk.md) / rushmoor.gov.uk
- [Salford City Council](/doc/source/salford_gov_uk.md) / salford.gov.uk
- [Sheffield City Council](/doc/source/sheffield_gov_uk.md) / sheffield.gov.uk
- [South Cambridgeshire District Council](/doc/source/scambs_gov_uk.md) / southderbyshire.gov.uk
- [South Derbyshire District Council](/doc/source/southderbyshire_gov_uk.md) / scambs.gov.uk
- [South Cambridgeshire District Council](/doc/source/scambs_gov_uk.md) / scambs.gov.uk
- [South Derbyshire District Council](/doc/source/southderbyshire_gov_uk.md) / southderbyshire.gov.uk
- [South Hams District Council](/doc/source/fccenvironment_co_uk.md) / southhams.gov.uk
- [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

View File

@@ -0,0 +1,104 @@
import datetime
import logging
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection
TITLE = "Moji odpadki, Ljubljana"
DESCRIPTION = "Source script for mojiodpadki.si"
URL = "https://www.mojiodpadki.si"
TEST_CASES = {
"DrzavniZbor": {"uprn": "1049"},
}
API_URL = "https://www.mojiodpadki.si/urniki/urniki-odvoza-odpadkov"
ICON_MAP = {
"MKO": "mdi:trash-can", # unsorted waste
"EMB": "mdi:recycle", # packaging waste
"BIO": "mdi:leaf", # biodegradable waste
"PAP": "mdi:newspaper", # paper waste
}
# month names from mojiodpadki.si (sl_SI)
MONTHS = {
"JANUAR": 1,
"FEBRUAR": 2,
"MAREC": 3,
"APRIL": 4,
"MAJ": 5,
"JUNIJ": 6,
"JULIJ": 7,
"AVGUST": 8,
"SEPTEMBER": 9,
"OKTOBER": 10,
"NOVEMBER": 11,
"DECEMBER": 12,
}
_LOGGER = logging.getLogger(__name__)
class Source:
def __init__(self, uprn):
_LOGGER.info(f"Initializing mojiodpadki.si waste collection service for uprn={uprn}")
self._uprn = uprn
def fetch(self):
# GET request returns schedule for matching uprn
url = f"{API_URL}/s/{self._uprn}"
_LOGGER.info(f"Getting mojiodpadki.si waste collection schedule for uprn={self._uprn}, url={url}")
r = requests.Session().get(url)
body = r.text
_LOGGER.debug(f"mojiodpadki.si waste collection schedule for uprn={self._uprn}: {body}")
# list that holds collection schedule
entries = []
# response is in HTML - parse it
soup = BeautifulSoup(body, "html.parser")
_LOGGER.debug(f"Parsed mojiodpadki.si response")
# find year in the head of the first document table
# <table class="calendar table-responsive">
# <thead>
# <tr>
# <td class="year fs-5 fw-bold" colspan="2">2023</td>
# ...
year = soup.table.thead.find("td", class_="year").string
_LOGGER.debug(f"found year={year}")
# find months, dates and waste tags in all document tables
for table in soup.find_all("table"):
# <table class="calendar table-responsive">
# <thead>
# ...
# <tr>
# <td class="month fs-5 fw-bold bg-primary text-light text-center" colspan="3">FEBRUAR</td>
month = table.thead.find("td", class_="month").string
_LOGGER.debug(f"found month={month}")
# <table class="calendar table-responsive">
# ...
# <tbody>
# <tr class="">
# <td class="day-number text-center">1</td>
# <td class="day-info text-end"><span class="small ms-1 badge tag pap" data-bs-toggle="tooltip" title="Papir in karton" tabindex="0">PAP</span>&nbsp;</td>
# ...
for tag in table.tbody.find_all("span", class_="tag"):
_LOGGER.debug(f"found tag={tag.string}")
day = tag.parent.parent.find("td", class_="day-number").string
_LOGGER.debug(f"found day={day}, tag={tag.string}, title={tag['title']}")
entries.append(
Collection(
date=datetime.date(int(year), MONTHS.get(month), int(day)),
t=tag["title"],
icon=ICON_MAP.get(tag.string)
)
)
return entries

View File

@@ -0,0 +1,42 @@
# Moji odpadki
Support for schedules provided by JAVNO PODJETJE VODOVOD KANALIZACIJA SNAGA d.o.o., Ljubljana, Slovenia: [Moji odpadki](https://www.mojiodpadki.si/urniki/urniki-odvoza-odpadkov)
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: mojiodpadki_si
args:
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER
```
### Configuration Variables
**uprn**
*(string) (required)*
This is required to unambiguously identify the property.
## Example using UPRN
```yaml
waste_collection_schedule:
sources:
- name: mojiodpadki_si
args:
uprn: "1049"
```
## How to find your `UPRN`
An easy way to find your Unique Property Reference Number (UPRN) is by going to
<https://www.mojiodpadki.si/urniki/urniki-odvoza-odpadkov> and entering in your address details.
UPRN is the last component of the URL once the schedule is displayed.
Example:
- Address: Šubičeva ulica 4
- Schedule URL: `https://www.mojiodpadki.si/urniki/urniki-odvoza-odpadkov/s/1049`
- UPRN: 1049

View File

@@ -26,6 +26,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| New Zealand | Auckland Council, Christchurch City Council, Gore, Invercargill & Southland, Horowhenua District Council, Waipa District Council, Wellington City Council |
| Norway | Min Renovasjon, Oslo Kommune |
| Poland | Ecoharmonogram, Warsaw |
| Slovenia | Moji odpadki, Ljubljana |
| Sweden | Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, 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 | Amber Valley Borough Council, 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, Chichester District 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, Maldon District Council, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire 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 |

View File

@@ -262,6 +262,10 @@ COUNTRYCODES = [
"code": "se",
"name": "Sweden",
},
{
"code": "si",
"name": "Slovenia",
},
{
"code": "ch",
"name": "Switzerland",