-
-
Notifications
You must be signed in to change notification settings - Fork 756
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
archon-dev
wants to merge
3
commits into
mampfes:master
Choose a base branch
from
archon-dev:pup_si
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Source: PUP si #3633
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
custom_components/waste_collection_schedule/waste_collection_schedule/source/pup_si.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.