Skip to content

Commit 8fe212e

Browse files
author
Alvaro Figueroa
committed
Printing nice message if loading the json fails on a county/state typo
1 parent e294aa4 commit 8fe212e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

PyPortal_Electioncal_US/electioncal_graphics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ def __init__(self, root_group, *, am_pm=True):
6868

6969

7070
def load_data(self, election_data):
71-
self.electioncal = json.loads(election_data)
72-
self.state_text.text = self.electioncal["dates"][1]["county"] + ", " + self.electioncal["dates"][0]["state"]
71+
try:
72+
self.electioncal = json.loads(election_data)
73+
self.state_text.text = self.electioncal["dates"][1]["county"] + ", " + self.electioncal["dates"][0]["state"]
74+
except ValueError:
75+
print("Error loading JSON data: Please check the configuration of county and state, in code.py")
76+
raise
7377

7478
def elections_cycle(self):
7579
self.update_time()

0 commit comments

Comments
 (0)