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

oil-tankstationer.dk parser failing #22

Open
mm98 opened this issue Aug 2, 2023 · 1 comment
Open

oil-tankstationer.dk parser failing #22

mm98 opened this issue Aug 2, 2023 · 1 comment

Comments

@mm98
Copy link

mm98 commented Aug 2, 2023

Hi,

It looks like https://www.oil-tankstationer.dk/de-gaeldende-braendstofpriser/ is breaking this integration. Which results in all fuelprices being unavailable. It seams like the required span tag (line 131) has been removed on their website.

def oil(self, url, products):
r = self._get_website(url)
html = self._get_html_soup(r)
rows = html.find_all("tr")
for productKey, productDict in products.items():
found = False
for row in rows:
if found:
continue
cells = row.find_all("td")
if cells:
found = productDict["name"] == self._cleanProductName(cells[0].text)
if found:
priceSegments = cells[2].findAll(
"span", style=["text-align:right;", "text-align:left;"]
)
products[productKey] = self._addPriceToProduct(
productDict,
priceSegments[0].text + "." + priceSegments[1].text,
)
return products

2023-08-01 17:40:39.131 ERROR (MainThread) [custom_components.fuelprices_dk.sensor] Unexpected error fetching sensor data: list index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 242, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fuelprices_dk/sensor.py", line 39, in async_update_data
    await hass.async_add_executor_job(company.refreshPrices)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_api.py", line 202, in refreshPrices
    self._products = getattr(self._parser, self._key)(self._url, self._products)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fuelprices_dk/fuelprices_dk_parsers.py", line 135, in oil
    priceSegments[0].text + "." + priceSegments[1].text,

Temporary fix for:

if found:
priceSegments = cells[2].findAll(
"span", style=["text-align:right;", "text-align:left;"]
)
products[productKey] = self._addPriceToProduct(
productDict,
priceSegments[0].text + "." + priceSegments[1].text,
)
return products

  if found:
    priceSegments = cells[2].findAll( 
      "span", style=["text-align:right;", "text-align:left;"] 
    )
+   if priceSegments:
+     products[productKey] = self._addPriceToProduct( 
+       productDict, 
+       priceSegments[0].text + "." + priceSegments[1].text, 
+     )
  return products 
tjuuljensen added a commit to tjuuljensen/Fuelprices_DK that referenced this issue Aug 3, 2023
@mm98
Copy link
Author

mm98 commented Aug 5, 2023

Fixed by pull request #23

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

No branches or pull requests

1 participant