Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Fix parsing of values > 1000
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Mar 21, 2020
1 parent 05a0a36 commit 056d9a4
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions custom_components/coronavirus_hessen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,10 @@ async def async_get_data():

try:
county = line[0].text.strip()
cases_str = line[1].text.strip()
deaths_str = line[3].text.strip()

if len(cases_str) and cases_str != "-":
cases = int(cases_str)
else:
cases = 0

if len(deaths_str) and deaths_str != "-":
deaths = int(deaths_str)
else:
deaths = 0
except ValueError:
_LOGGER.error("Error processing line {}, skipping".format(line))
cases = parse_num(line[1].text.strip())
deaths = parse_num(line[3].text.strip())
except:
_LOGGER.exception("Error processing line {}, skipping".format(line))
continue

if county == "Gesamt":
Expand All @@ -112,3 +102,9 @@ async def async_get_data():
)
await hass.data[DOMAIN].async_refresh()
return hass.data[DOMAIN]


def parse_num(s, t=int):
if len(s) and s != "-":
return t(s.replace(".", "").replace(",", "."))
return 0

0 comments on commit 056d9a4

Please sign in to comment.