Skip to content

Commit 39336f1

Browse files
committed
Allow local applications database for testing
1 parent 730a507 commit 39336f1

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

code.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
SCREENSAVERS_CATEGORY = "Screensavers"
5555

56+
APPLICATIONS_PATH = "applications.json" # used for testing
5657
APPLICATIONS_URL = "https://raw.githubusercontent.com/relic-se/Fruit_Jam_Library/refs/heads/main/database/applications.json"
5758
METADATA_URL = "https://raw.githubusercontent.com/{:s}/refs/heads/main/metadata.json"
5859
REPO_URL = "https://api.github.com/repos/{:s}"
@@ -367,18 +368,25 @@ def log(msg: str) -> None:
367368
status_label.text = msg
368369
print(msg)
369370

370-
# download applications database
371+
# use local or download applications database
371372
try:
372-
applications = json.loads(fj.fetch(
373-
APPLICATIONS_URL,
374-
force_content_type=adafruit_fruitjam.network.CONTENT_JSON,
375-
timeout=10,
376-
))
377-
if type(applications) is int:
378-
raise ValueError("{:d} response".format(applications))
373+
with open(APPLICATIONS_PATH, "r") as f:
374+
applications = json.load(f)
375+
if not isinstance(applications, dict):
376+
raise ValueError("Invalid format")
379377
except (OSError, ValueError, AttributeError) as e:
380-
log("Unable to fetch applications database! {:s}".format(str(e)))
381-
reset(3)
378+
log("Unable to read local applications database. {:s}".format(str(e)))
379+
try:
380+
applications = json.loads(fj.fetch(
381+
APPLICATIONS_URL,
382+
force_content_type=adafruit_fruitjam.network.CONTENT_JSON,
383+
timeout=10,
384+
))
385+
if type(applications) is int:
386+
raise ValueError("{:d} response".format(applications))
387+
except (OSError, ValueError, AttributeError) as e:
388+
log("Unable to fetch applications database! {:s}".format(str(e)))
389+
reset(3)
382390

383391
categories = sorted(applications.keys())
384392
selected_category = None

0 commit comments

Comments
 (0)