Skip to content

Commit dcd5f0d

Browse files
committed
Fix parsing the vaccination data
The code apparently broke when a new column was added to the CSV data to show the number of boosters. This field is blank in the US data, so the code would crash trying to turn the empty string into an integer. Since upstream seems to add columns at the far right (a sensible choice) we should index using positive numbers instead. This also changes the code so that in the event of a failure it actually *DOES* retry. I designed it to wait for 1 hour in deep sleep before retrying, so that it doesn't immediately run down the battery in case of transient errors.
1 parent c7471f8 commit dcd5f0d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

MagTag_Covid_Vaccination/code.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
value = magtag.fetch().split("\n")[-2].split(",")
5959
print("Response is", value)
6060

61-
vaccinated = int(value[-2]) / 331984513
62-
fully_vaccinated = int(value[-1]) / 331984513
61+
vaccinated = int(value[7]) / 331984513
62+
fully_vaccinated = int(value[8]) / 331984513
6363

6464
magtag.set_text(f"{value[0]} Vaccination Rates", 0, False)
6565
magtag.set_text(value[1], 1, False)
@@ -74,8 +74,11 @@
7474
magtag.refresh()
7575

7676
seconds_to_sleep = 24 * 60 * 60 # Sleep for one day
77-
print(f"Sleeping for {seconds_to_sleep} seconds")
78-
magtag.exit_and_deep_sleep(seconds_to_sleep)
7977

8078
except (ValueError, RuntimeError) as e:
81-
print("Some error occured, retrying! -", e)
79+
print("Some error occured, retrying in one hour! -", e)
80+
seconds_to_sleep = 60 * 60 # Sleep for one hour
81+
82+
print(f"Sleeping for {seconds_to_sleep} seconds")
83+
magtag.exit_and_deep_sleep(seconds_to_sleep)
84+

0 commit comments

Comments
 (0)