diff --git a/mason-today/__init__.py b/mason-today/__init__.py index 68d25d1104530a42c738f20596871bfa97d1341d..e3ca726cad863bfd81522f924bf02673840504ed 100644 --- a/mason-today/__init__.py +++ b/mason-today/__init__.py @@ -4,7 +4,7 @@ from flask import Response from flask import render_template # app imports -from appmethods import updatebothdbs, runscheduleloop +from appmethods import update_both_dbs, run_schedule_loop from redisactions import redisdb # python imports @@ -40,13 +40,13 @@ def display_GC_data(): @app.route("/api/lastupdate") -def getlastupdate(): +def get_last_update(): resp = Response(redisdb.lindex("dbupdatelog", 0).replace("\n", "
")) return resp try: - thread.start_new_thread(runscheduleloop, ()) + thread.start_new_thread(run_schedule_loop, ()) print "started thread!" except: print "===================================================" \ diff --git a/mason-today/appmethods.py b/mason-today/appmethods.py index c2c29d19256bdf87191087de83c066af2833a630..2a013031d85dd30038834a2b94188550ceae096f 100644 --- a/mason-today/appmethods.py +++ b/mason-today/appmethods.py @@ -1,6 +1,6 @@ # app imports from parscript import load_data -from getconnectedscript import load_getconn_data +from getconnectedscript import load_gc_data import redisactions as f # python imports @@ -14,27 +14,24 @@ import schedule # attempts to update both dbs and logs the result -def updatebothdbs(): - livesuccess = f.livedbfill(json.dumps(load_data(), ensure_ascii=False)) - gcsuccess = f.gcdbfill(json.dumps(load_getconn_data(), ensure_ascii=False)) +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(datetime.datetime.now()) \ + "\n\nAttempted to update cache." \ + "\n25Live: " + str(livesuccess) \ + "\nGC: " + str(gcsuccess) - f.appendtoupdatelog(successLog) + f.append_to_update_log(successLog) return successLog -def testprint(): - print "Schedule action completed!" - - # setting up cacheing -schedule.every().day.at("02:00").do(updatebothdbs) +# this must be done after the update_both_dbs def +schedule.every().day.at("02:00").do(update_both_dbs) -def runscheduleloop(): +def run_schedule_loop(): runScheduler = True while runScheduler: schedule.run_pending() diff --git a/mason-today/getconnectedscript.py b/mason-today/getconnectedscript.py index 38e298d88818a56041241e6ec52314a780a1a917..f6554ecde4c78890909bb3635fa9bc766178641f 100644 --- a/mason-today/getconnectedscript.py +++ b/mason-today/getconnectedscript.py @@ -25,7 +25,7 @@ def splitAndConvertTime(strin): return returnlist -def load_getconn_data(): +def load_gc_data(): feedtext = requests.get( "https://getconnected.gmu.edu/events/events.rss").text feedtext = cleanup(feedtext) diff --git a/mason-today/redisactions.py b/mason-today/redisactions.py index aab5c2b27b683c0f589c28db9b945921a728aa9f..b45c1dd13e7ba4cb364c79afba3d86d693f274a0 100644 --- a/mason-today/redisactions.py +++ b/mason-today/redisactions.py @@ -15,13 +15,14 @@ import redis # 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 gcdbfill(dictlist): +def gc_db_fill(dictlist): success = redisdb.set("gcdict", dictlist) log = str(datetime.datetime.now()) @@ -33,7 +34,7 @@ def gcdbfill(dictlist): # saves new dictlist in place of previous 25Live dictlist # returns true if the dictlist is not empty, false otherwise -def livedbfill(dictlist): +def live_db_fill(dictlist): success = redisdb.set("livedict", dictlist) log = str(datetime.datetime.now()) @@ -45,7 +46,7 @@ def livedbfill(dictlist): # appends the log string to the head of our update long # returns true if the head is the newest update -def appendtoupdatelog(logstring): +def append_to_update_log(logstring): redisdb.lpush("dbupdatelog", logstring) return redisdb.lindex("dbupdatelog", 0) == logstring