Added a more sophisticated json loading interface

- this should provide more verbose output in the case that the json file
  either doesn't exist or isn't formatted correctly
This commit is contained in:
Ariana Giroux 2022-07-24 14:33:09 -06:00
parent e4fe12befe
commit 517c1b071d
1 changed files with 12 additions and 1 deletions

13
app.py
View File

@ -32,10 +32,21 @@ structure:
import chevron
import requests
import json
from os import path
from pprint import pprint
from flask import Flask, request
stream_data = json.load(open('resources/data.json', 'r'))
# load json data, or raise exception.
if path.exists('resources/data.json'):
try:
stream_data = json.load(open('resources/data.json', 'r'))
except json.JSONDecodeError as e:
raise RuntimeError('JSON data did not pass validation.')
else:
raise RuntimeError('Could not find ./resources/data.json, required for '
'runtime!')
# initialize requests session
session = requests.Session()
session.auth = ('admin', stream_data['stream_key'])