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

New Source: PUP si #3633

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,7 @@ If your service provider is not listed, feel free to open a [source request issu
<summary>Slovenia</summary>

- [Moji odpadki, Ljubljana](/doc/source/mojiodpadki_si.md) / mojiodpadki.si
- [PUP Saubermacher](/doc/source/pup_si.md) / pup-saubermacher.si
- [Snaga Maribor](/doc/source/snaga_mb_si.md) / snaga-mb.si
</details>

Expand Down
6 changes: 6 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -12942,6 +12942,12 @@
"default_params": {},
"id": "mojiodpadki_si"
},
{
"title": "PUP Saubermacher",
"module": "pup_si",
"default_params": {},
"id": "pup_si"
},
{
"title": "Snaga Maribor",
"module": "snaga_mb_si",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -11319,6 +11319,26 @@
"uprn": "Eine einfache Möglichkeit, Ihre Unique Property Reference Number (UPRN) zu finden, besteht darin, auf https://www.findmyaddress.co.uk/ zu gehen und Ihre Adressdaten einzugeben."
}
},
"args_pup_si": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md",
"data": {
"calendar_title": "Kalender Titel",
"place_id": "Place Id"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_pup_si": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md",
"data": {
"calendar_title": "Kalender Titel",
"place_id": "Place Id"
},
"data_description": {}
},
"args_snaga_mb_si": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11361,6 +11361,26 @@
"uprn": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details."
}
},
"args_pup_si": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md.",
"data": {
"calendar_title": "Calendar Title",
"place_id": "Place Id"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used."
}
},
"reconfigure_pup_si": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md.",
"data": {
"calendar_title": "Calendar Title",
"place_id": "Place Id"
},
"data_description": {}
},
"args_snaga_mb_si": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md.",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11270,6 +11270,26 @@
"uprn": "Une manière simple de retrouver votre numéro unique de propriété (UPRN) est de vous rendre sur https://www.findmyaddress.co.uk/ et de saisir les détails de votre adresse."
}
},
"args_pup_si": {
"title": "Configurer la Source",
"description": "Configurez votre fournisseur de services. Plus de détails : https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md.",
"data": {
"calendar_title": "Titre du Calendrier",
"place_id": "Place Id"
},
"data_description": {
"calendar_title": "Un nom plus lisible ou convivial pour le calendrier des déchets. Si aucun n'est fourni, le nom renvoyé par la source sera utilisé."
}
},
"reconfigure_pup_si": {
"title": "Reconfigurer la Source",
"description": "Configurez votre fournisseur de services. Plus de détails : https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md.",
"data": {
"calendar_title": "Titre du Calendrier",
"place_id": "Place Id"
},
"data_description": {}
},
"args_snaga_mb_si": {
"title": "Configurer la Source",
"description": "Configurez votre fournisseur de services. Plus de détails : https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md.",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -11277,6 +11277,26 @@
"uprn": "Un modo facile per scoprire il tuo Numero di Riferimento Proprietà Unica (UPRN) è andare su https://www.findmyaddress.co.uk/ e inserire i dettagli del tuo indirizzo."
}
},
"args_pup_si": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md.",
"data": {
"calendar_title": "Nome Calendario",
"place_id": "Place Id"
},
"data_description": {
"calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi."
}
},
"reconfigure_pup_si": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pup_si.md.",
"data": {
"calendar_title": "Nome Calendario",
"place_id": "Place Id"
},
"data_description": {}
},
"args_snaga_mb_si": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/snaga_mb_si.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import requests
from bs4 import BeautifulSoup
from datetime import datetime
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "PUP Saubermacher"
DESCRIPTION = "Source for PUP Saubermacher."
URL = "https://www.pup-saubermacher.si/"
TEST_CASES = {
"Sostanj 1": {"place_id": 412177},
"Sostanj 2": {"place_id": 100911},
}

BIN_TYPES = {
"M": "Mesani",
"B": "Bioloski",
"E": "Embalaza",
}
ICON_MAP = {
"M": "mdi:trash-can",
"B": "mdi:leaf",
"E": "mdi:recycle",
}

BASE_URL = "https://www.pup-saubermacher.si/php/dobi_tabelo.php"


class Source:
def __init__(self, place_id: int):
self._place_id: int = place_id

def fetch(self) -> list[Collection]:
args = {
"q": self._place_id,
}
response = requests.get(BASE_URL, params=args)
response.encoding = 'utf-8'
response.raise_for_status()

content = BeautifulSoup(response.text, "html.parser")

if response.text == "null" or not content.find_all("ul"):
raise Exception("Invalid place id")

entries = []
data = self.parse_to_obj(content)

for item in data:
type_char = self.get_type(item["title"])

for date_info in item["dates"]:
date = self.get_date(date_info)

if date is not None:
entries.append(Collection(date, BIN_TYPES[type_char], ICON_MAP[type_char]))

return entries

def parse_to_obj(self, content):
# Find all <b> tags and their following <ul> tags
b_tags = content.find_all('b')[2:] # Skip the first two <b> tags
data = []

for b_tag in b_tags:
title = b_tag.get_text()
ul_tag = b_tag.find_next_sibling('ul')

if ul_tag:
dates = [line.strip() for line in ul_tag.decode_contents().split('<br>') if line.strip()]
data.append({"title": title, "dates": dates[0].split("<br/>")})

return data

def get_type(self, title):
if title.startswith("Mešana embalaža"):
return "E"
elif title.startswith("Mešani komunalni odpadki"):
return "M"
else:
return "B"

def get_date(self, date_info):
parsed_date = date_info.split(" ")

if isinstance(parsed_date, list) and len(parsed_date) == 1:
return None
else:
date_obj = datetime.strptime(parsed_date[0].strip(), "%d.%m.%Y")
return date_obj.date()
36 changes: 36 additions & 0 deletions doc/source/pup_si.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Simbio

Support for schedules provided by [Simbio](https://www.simbio.si/sl/), serving Simbio, Slovenia.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: pup_si
args:
place_id: ODJEMNO MESTO (številka)
```

### Configuration Variables

**place_id**
*(Integer) (required)*


## Example

```yaml
waste_collection_schedule:
sources:
- name: pup_si
args:
place_id: 12345

```

## How to get the source argument

Find the parameter of your place id written on you monthly bill for PUP. The number is written on the right side of "Odjemno mesto:" row.

For more information follow go to PUP website [https://www.pup-saubermacher.si/index.php/domov/urnik-odvoza-odpadkov](https://www.pup-saubermacher.si/index.php/domov/urnik-odvoza-odpadkov).
Comment on lines +34 to +36
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also be placed in the HOW_TO_GET_ARGUMENTS_DESCRIPTION attribute, so it appears in the GUI Config.

Loading
Loading