Commit 60e4d24d authored by Landon DeCoito's avatar Landon DeCoito

started database implementation. added redisactions.py to facilitate that

parent f4c6fb68
......@@ -10,8 +10,15 @@ from getconnectedscript import load_getconn_data
# python imports
import json
# other imports
import redis
from redisactions import *
# setting up flask instance
app = Flask(__name__)
# setting up redis database
redisdb = redis.from_url("redis://localhost:6379/0", db=0)
@app.route("/")
def display_default():
......@@ -21,15 +28,15 @@ def display_default():
@app.route("/api/25live")
def display_data():
resp = Response(json.dumps(load_data(), ensure_ascii=False)
.encode('utf-8'))
livedbfill(json.dumps(load_data(), ensure_ascii=False))
resp = Response(redisdb.get("livedict")) # .encode('utf-8'))
resp.headers['Content-Type'] = 'application/json; charset=utf-8'
return resp
@app.route("/api/getconnected")
def display_GC_data():
resp = Response(json.dumps(load_getconn_data(), ensure_ascii=False)
.encode('utf-8'))
gcdbfill(json.dumps(load_getconn_data(), ensure_ascii=False))
resp = Response(redisdb.get("gcdict")) # .encode('utf-8'))
resp.headers['Content-Type'] = 'application/json; charset=utf-8'
return resp
# third party imports
import redis
from __init__ import redisdb
# I'm thinking we store a couple things
# first: a key-value where the value is the dictlist
# second: a k-v for a list of errored events
# use rpush(key, value) to append a dblist (rpushx() to check if it exists)
# use del(key) to remove a k-v
# so we everytime we run parscript or gcscript we want to run a dbfill()
# function. and every time we find an error we want to run a dberrorfill()
# function.
# this will update the
# returns true if the dictlist is not empty, false otherwise
def gcdbfill(dictlist):
try:
redisdb.set("gcdict", dictlist)
except e:
return False
if redisdb.get("gcdict") is not None:
return True
else:
return False
# saves new dictlist in place of previous 25Live dictlist
# returns true if the dictlist is empty, false otherwise
def livedbfill(dictlist):
try:
redisdb.set("livedict", dictlist)
except e:
return False
if redisdb.get("livedict") is not None:
return True
else:
return False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment