J-Lindvig/Fuelprices_DK

oil-tankstationer.dk parser failing

Opened this issue · 1 comments

mm98 commented

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 
mm98 commented

Fixed by pull request #23