|
53 | 53 |
|
54 | 54 | SCREENSAVERS_CATEGORY = "Screensavers" |
55 | 55 |
|
| 56 | +APPLICATIONS_PATH = "applications.json" # used for testing |
56 | 57 | APPLICATIONS_URL = "https://raw.githubusercontent.com/relic-se/Fruit_Jam_Library/refs/heads/main/database/applications.json" |
57 | 58 | METADATA_URL = "https://raw.githubusercontent.com/{:s}/refs/heads/main/metadata.json" |
58 | 59 | REPO_URL = "https://api.github.com/repos/{:s}" |
@@ -367,18 +368,25 @@ def log(msg: str) -> None: |
367 | 368 | status_label.text = msg |
368 | 369 | print(msg) |
369 | 370 |
|
370 | | -# download applications database |
| 371 | +# use local or download applications database |
371 | 372 | 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") |
379 | 377 | 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) |
382 | 390 |
|
383 | 391 | categories = sorted(applications.keys()) |
384 | 392 | selected_category = None |
|
0 commit comments