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:
parent
e4fe12befe
commit
517c1b071d
13
app.py
13
app.py
|
@ -32,10 +32,21 @@ structure:
|
||||||
import chevron
|
import chevron
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
from os import path
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from flask import Flask, request
|
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 = requests.Session()
|
||||||
session.auth = ('admin', stream_data['stream_key'])
|
session.auth = ('admin', stream_data['stream_key'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue