From 056d9a407167b13c165ba7bdece4f00f4ec27f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sat, 21 Mar 2020 23:19:39 +0100 Subject: [PATCH] Fix parsing of values > 1000 --- .../coronavirus_hessen/__init__.py | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/custom_components/coronavirus_hessen/__init__.py b/custom_components/coronavirus_hessen/__init__.py index ba179df..7592a22 100644 --- a/custom_components/coronavirus_hessen/__init__.py +++ b/custom_components/coronavirus_hessen/__init__.py @@ -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": @@ -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 \ No newline at end of file