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

Added support for Komorniki and Kostrzyn commune in Poland (zys_harmonogram_pl) - fix for loop and add auto NAME_MAP #3832

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

sematuszewski
Copy link

Hello,

i fixed for loop and added auto NAME_MAP with uff-8 fix for this source.

@sematuszewski sematuszewski changed the title Added support for Komorniki and Kostrzyn commune in Poland - fix for loop and add auto NAME_MAP Added support for Komorniki and Kostrzyn commune in Poland (zys_harmonogram_pl) - fix for loop and add auto NAME_MAP Feb 25, 2025
_LOGGER.debug(
f"fetch failed for source {TITLE}: trying different API_URL ..."
)
return self.get_data(API_URL.format(""))
Copy link
Collaborator

Choose a reason for hiding this comment

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

requires two format arguments only one given

Copy link
Author

Choose a reason for hiding this comment

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

I fixed this :)

if item["value"] == self._city:
city_id = item["id"]
if city_id == 0:
raise Exception("city not found")
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could raise here, for street and for number SourceArgumentNotFoundWithSuggestions (from waste_collection_schedule.exceptions import SourceArgumentNotFoundWithSuggestions)

With raise SourceArgumentNotFoundWithSuggestions("city", self._city, [c["value"] for c in cities] ) This way you'll get a more detailed error message and for GUI configuration you'll see a drop-down of all available cities/streets/house_numbers if it fails.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your suggestion, I will improve the code when I have some free time :)

import datetime
import json
import logging
import defusedxml.ElementTree as XMLDEFUSE
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a dependency of this module and adding addtional dependencies should only be done when really neccesary. You could use BeatuifulSoup with "xml" parsing, It should probably work pretty much the same:

from bs4 import BeautifulSoup
[...]
tree = BeautifulSoup(table, "xml")

Copy link
Author

Choose a reason for hiding this comment

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

I replaced XMLDEFUSE to BeautifulSoup

@5ila5
Copy link
Collaborator

5ila5 commented Mar 5, 2025

The test case only works when fixing the format issue.

sematuszewski and others added 2 commits March 5, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants