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 more debugging #73

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
6 changes: 6 additions & 0 deletions pytrafikverket/trafikverket.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def get_text(self, field: str) -> str | None:
return None
if len(nodes) > 1:
raise ValueError("Found multiple nodes should only 0 or 1 is allowed")
LOGGER.debug("Return text value %s", nodes[0].text)
value: str = nodes[0].text
return value

Expand All @@ -223,6 +224,7 @@ def get_number(self, field: str) -> float | None:
return None
if len(nodes) > 1:
raise ValueError("Found multiple nodes should only 0 or 1 is allowed")
LOGGER.debug("Return number value %s", nodes[0].text)
try:
value = float(nodes[0].text)
except ValueError:
Expand All @@ -237,6 +239,7 @@ def get_texts(self, field: str) -> list[str] | None:
result = []
for line in nodes:
result.append(line.text)
LOGGER.debug("Return texts value %s", result)
return result

def get_datetime_for_modified(self, field: str) -> datetime | None:
Expand All @@ -251,6 +254,7 @@ def get_datetime_for_modified(self, field: str) -> datetime | None:
return None
if len(nodes) > 1:
raise ValueError("Found multiple nodes should only 0 or 1 is allowed")
LOGGER.debug("Return modified value %s", nodes[0].text)
return datetime.strptime(
nodes[0].text, Trafikverket.date_time_format_for_modified
)
Expand All @@ -264,6 +268,7 @@ def get_datetime(self, field: str) -> datetime | None:
return None
if len(nodes) > 1:
raise ValueError("Found multiple nodes should only 0 or 1 is allowed")
LOGGER.debug("Return datetime value %s", nodes[0].text)
return datetime.strptime(nodes[0].text, Trafikverket.date_time_format)

def get_bool(self, field: str) -> bool:
Expand All @@ -275,5 +280,6 @@ def get_bool(self, field: str) -> bool:
return False
if len(nodes) > 1:
raise ValueError("Found multiple nodes should only 0 or 1 is allowed")
LOGGER.debug("Return bool value %s", nodes[0].text)
value: bool = nodes[0].text.lower() == "true"
return value