Commit 0f69a429 authored by Landon DeCoito's avatar Landon DeCoito
Browse files

Merge branch '4-get-redis' into 'master'

Resolve "Get redis"

Closes #4

See merge request !33
parents cf1112d3 72cfd150
......@@ -17,3 +17,7 @@ Step 3 - Create a web page that list out all the events and change what are pres
1) Create a `virtualenv` if you know what that is
2) Install the project's dependencies by running `pip install -r requirements.txt`
3) Start the Flask development server by running `./`
# Documentation for the packages we use
* Schedule
* redis-py
\ No newline at end of file
......@@ -4,12 +4,18 @@ from flask import Response
from flask import render_template
# app imports
from parscript import load_data
from getconnectedscript import load_getconn_data
from appmethods import update_both_dbs, run_schedule_loop
from redisactions import redisdb
# python imports
import json
import thread
# other imports
import redis
# setting up flask instance
app = Flask(__name__)
......@@ -21,15 +27,31 @@ def display_default():
def display_data():
resp = Response(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
def display_GC_data():
resp = Response(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
def get_last_update():
resp = Response(redisdb.lindex("dbupdatelog", 0).replace("\n", "</br>"))
return resp
# make sure the cacheing is set up on init
thread.start_new_thread(run_schedule_loop, ())
print "started thread!"
print "===================================================" \
+ "Unable to start scheduling thread" \
+ "==================================================="
# app imports
from parscript import load_data
from getconnectedscript import load_gc_data
import redisactions as f
# python imports
import json
import datetime
import time
# other imports
import redis
import schedule
# attempts to update both dbs and logs the result
def update_both_dbs():
livesuccess = f.live_db_fill(json.dumps(load_data(), ensure_ascii=False))
gcsuccess = f.gc_db_fill(json.dumps(load_gc_data(), ensure_ascii=False))
successLog = str( \
+ "\n\nAttempted to update cache." \
+ "\n25Live: " + str(livesuccess) \
+ "\nGC: " + str(gcsuccess)
return successLog
# setting up cacheing
# this must be done after the update_both_dbs def
def run_schedule_loop():
runScheduler = True
while runScheduler:
......@@ -25,7 +25,7 @@ def splitAndConvertTime(strin):
return returnlist
def load_getconn_data():
def load_gc_data():
feedtext = requests.get(
feedtext = cleanup(feedtext)
# python imports
import datetime
# other imports
import redis
# 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 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.
# setting up redis database
redisdb = redis.from_url("redis://localhost:6379/0", db=0)
# this will update the live dictlist and the cachedate
# returns true if the dictlist is not empty, false otherwise
def gc_db_fill(dictlist):
success = redisdb.set("gcdict", dictlist)
log = str(
redisdb.set("gccachedate", log)
success = redisdb.get("gccachedate") == log and success
return redisdb.get("gcdict") is not None and success
# saves new dictlist in place of previous 25Live dictlist
# returns true if the dictlist is not empty, false otherwise
def live_db_fill(dictlist):
success = redisdb.set("livedict", dictlist)
log = str(
redisdb.set("livecachedate", log)
success = redisdb.get("livecachedate") == log and success
return redisdb.get("livedict") is not None and success
# appends the log string to the head of our update long
# returns true if the head is the newest update
def append_to_update_log(logstring):
redisdb.lpush("dbupdatelog", logstring)
return redisdb.lindex("dbupdatelog", 0) == logstring
......@@ -10,8 +10,11 @@ itsdangerous==0.24
export FLASK_APP=mason-today/
export FLASK_DEBUG=1
export FLASK_DEBUG=0
flask run
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