Skip to content

Commit

Permalink
fix: add logger to debug rest api #11
Browse files Browse the repository at this point in the history
  • Loading branch information
chilikla authored Nov 26, 2024
1 parent 0d444e8 commit 12906cf
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions custom_components/yerushamayim/data_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ def __init__(self, hass: HomeAssistant):
)

# Initialize REST clients
headers = {
generic_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
rest_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Connection": "keep-alive",
}

self.site = RestData(
hass,
Expand All @@ -57,7 +63,7 @@ def __init__(self, hass: HomeAssistant):
"UTF-8",
None,
None,
headers,
generic_headers,
None,
False,
"python_default"
Expand All @@ -70,7 +76,7 @@ def __init__(self, hass: HomeAssistant):
"UTF-8",
None,
None,
headers,
generic_headers,
None,
False,
"python_default"
Expand All @@ -83,7 +89,7 @@ def __init__(self, hass: HomeAssistant):
"UTF-8",
None,
None,
headers,
rest_headers,
None,
False,
"python_default"
Expand Down Expand Up @@ -178,21 +184,23 @@ def _extract_data(self) -> YerushamayimData:
_LOGGER.debug("REST API data exists: %s", bool(self.rest_api.data))
_LOGGER.debug("REST API data type: %s", type(self.rest_api.data))
_LOGGER.debug("REST API data content: %r", self.rest_api.data) # Using %r for raw representation
_LOGGER.debug("REST API content: %r", self.rest_api)

if self.rest_api.data:
try:
_LOGGER.debug("Raw REST API data: %s", self.rest_api.data)

rest_data = {}
for line in self.rest_api.data.strip().split('\n'):
_LOGGER.debug("Processing line: %s", line)
parts = line.split('\t')
if len(parts) >= 3:
key = parts[1].split(':')[0].strip()
value = parts[2].strip()
rest_data[key] = value
_LOGGER.debug("Added key-value: %s = %s", key, value)
for row in soup.find_all('tr'):
_LOGGER.debug("Processing row: %s", row)
columns = row.find_all('td')
if len(columns) >= 2:
# Skip the index column (columns[0]) and split the second column
key_value = columns[1].text.split(':')
if len(key_value) == 2:
key = key_value[0].strip()
value = key_value[1].strip()
rest_data[key] = value
_LOGGER.debug("Added key-value: %s = %s", key, value)

_LOGGER.debug("Processed REST data: %s", rest_data)

Expand Down

0 comments on commit 12906cf

Please sign in to comment.