|
2 | 2 | from adafruit_progressbar.progressbar import ProgressBar |
3 | 3 |
|
4 | 4 | # Set up where we'll be fetching data from |
5 | | -DATA_SOURCE = "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/country_data/United%20States.csv" |
| 5 | +DATA_SOURCE = "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/country_data/United%20States.csv" # pylint: disable=line-too-long |
6 | 6 | # Find data for other countries/states here: |
7 | 7 | # https://github.com/owid/covid-19-data/tree/master/public/data/vaccinations |
8 | 8 |
|
|
11 | 11 |
|
12 | 12 | magtag.add_text( |
13 | 13 | text_font="/fonts/ncenR14.pcf", |
14 | | - text_position=((magtag.graphics.display.width // 2) - 1, 8,), |
| 14 | + text_position=( |
| 15 | + (magtag.graphics.display.width // 2) - 1, |
| 16 | + 8, |
| 17 | + ), |
15 | 18 | text_anchor_point=(0.5, 0.5), |
16 | 19 | is_data=False, |
17 | 20 | ) # Title |
18 | 21 |
|
19 | 22 | magtag.add_text( |
20 | 23 | text_font="/fonts/ncenR14.pcf", |
21 | | - text_position=((magtag.graphics.display.width // 2) - 1, 23,), |
| 24 | + text_position=( |
| 25 | + (magtag.graphics.display.width // 2) - 1, |
| 26 | + 23, |
| 27 | + ), |
22 | 28 | text_anchor_point=(0.5, 0.5), |
23 | 29 | is_data=False, |
24 | 30 | ) # Date |
25 | 31 |
|
26 | 32 | magtag.add_text( |
27 | 33 | text_font="/fonts/ncenR14.pcf", |
28 | | - text_position=((magtag.graphics.display.width // 2) - 1, 40,), |
| 34 | + text_position=( |
| 35 | + (magtag.graphics.display.width // 2) - 1, |
| 36 | + 40, |
| 37 | + ), |
29 | 38 | text_anchor_point=(0.5, 0.5), |
30 | 39 | is_data=False, |
31 | 40 | ) # Vaccinated text |
32 | 41 |
|
33 | 42 | magtag.add_text( |
34 | 43 | text_font="/fonts/ncenR14.pcf", |
35 | | - text_position=((magtag.graphics.display.width // 2) - 1, 85,), |
| 44 | + text_position=( |
| 45 | + (magtag.graphics.display.width // 2) - 1, |
| 46 | + 85, |
| 47 | + ), |
36 | 48 | text_anchor_point=(0.5, 0.5), |
37 | 49 | is_data=False, |
38 | 50 | ) # Fully vaccinated text |
|
54 | 66 | magtag.graphics.set_background("/bmps/background.bmp") |
55 | 67 |
|
56 | 68 |
|
| 69 | +def l_split(line): |
| 70 | + line_list = [] |
| 71 | + print(line) |
| 72 | + while "," in line: |
| 73 | + if line[0] == '"': |
| 74 | + temp = line.split('"', 2)[1] |
| 75 | + line_list.append(temp) |
| 76 | + line = line.split('"', 2)[2][1:] |
| 77 | + else: |
| 78 | + temp, line = line.split(",", 1) |
| 79 | + line_list.append(temp) |
| 80 | + line_list.append(line) |
| 81 | + return line_list |
| 82 | + |
| 83 | + |
57 | 84 | try: |
58 | | - value = magtag.fetch().split("\n")[-2].split(",") |
| 85 | + table = magtag.fetch().split("\n") |
| 86 | + columns = l_split(table[0]) |
| 87 | + latest = l_split(table[-2]) |
| 88 | + print(columns) |
| 89 | + print(latest) |
| 90 | + value = dict(zip(columns, latest)) |
59 | 91 | print("Response is", value) |
| 92 | + print(value) |
60 | 93 |
|
61 | | - vaccinated = int(value[7]) / 331984513 |
62 | | - fully_vaccinated = int(value[8]) / 331984513 |
| 94 | + vaccinated = int(value["people_vaccinated"]) / 331984513 |
| 95 | + fully_vaccinated = int(value["people_fully_vaccinated"]) / 331984513 |
63 | 96 |
|
64 | | - magtag.set_text(f"{value[0]} Vaccination Rates", 0, False) |
65 | | - magtag.set_text(value[2], 1, False) |
| 97 | + magtag.set_text(f"{value['location']} Vaccination Rates", 0, False) |
| 98 | + magtag.set_text(value["date"], 1, False) |
66 | 99 | magtag.set_text("Vaccinated: {:.2f}%".format(vaccinated * 100), 2, False) |
67 | 100 | magtag.set_text( |
68 | 101 | "Fully Vaccinated: {:.2f}%".format(fully_vaccinated * 100), 3, False |
|
73 | 106 |
|
74 | 107 | magtag.refresh() |
75 | 108 |
|
76 | | - seconds_to_sleep = 24 * 60 * 60 # Sleep for one day |
| 109 | + SECONDS_TO_SLEEP = 24 * 60 * 60 # Sleep for one day |
77 | 110 |
|
78 | 111 | except (ValueError, RuntimeError) as e: |
79 | 112 | print("Some error occured, retrying in one hour! -", e) |
80 | 113 | seconds_to_sleep = 60 * 60 # Sleep for one hour |
81 | 114 |
|
82 | | -print(f"Sleeping for {seconds_to_sleep} seconds") |
83 | | -magtag.exit_and_deep_sleep(seconds_to_sleep) |
84 | | - |
| 115 | +print(f"Sleeping for {SECONDS_TO_SLEEP} seconds") |
| 116 | +magtag.exit_and_deep_sleep(SECONDS_TO_SLEEP) |
0 commit comments