__init__.py 1.34 KB
Newer Older
1
# flask imports
2
from flask import Flask
Zach Osman's avatar
Zach Osman committed
3
from flask import Response
4 5 6
from flask import render_template

# app imports
7 8
from appmethods import updatebothdbs
from redisactions import redisdb
9 10

# python imports
11
import json
12
# import time
13

14 15
# other imports
import redis
16
import schedule
17

18 19

# setting up flask instance
20 21
app = Flask(__name__)

22 23 24 25 26
# setting up cacheing
schedule.every().day.at("02:00").do(updatebothdbs)
# schedule.every(5).seconds.do(updatebothdbs)


Landon DeCoito's avatar
Landon DeCoito committed
27 28
@app.route("/")
def display_default():
29
    resp = render_template('welcomepage.html')
30
    return resp
Landon DeCoito's avatar
Landon DeCoito committed
31

32

33
@app.route("/api/25live")
34
def display_data():
35
    resp = Response(redisdb.get("livedict"))  # .encode('utf-8'))
Zach Osman's avatar
Zach Osman committed
36 37
    resp.headers['Content-Type'] = 'application/json; charset=utf-8'
    return resp
38

Landon DeCoito's avatar
Landon DeCoito committed
39

40
@app.route("/api/getconnected")
41
def display_GC_data():
42
    resp = Response(redisdb.get("gcdict"))  # .encode('utf-8'))
43 44
    resp.headers['Content-Type'] = 'application/json; charset=utf-8'
    return resp
45

46 47 48 49 50 51 52 53 54 55 56

@app.route("/updatedbs")
def updateroute():
    return Response(updatebothdbs().replace("\n","</br>"))


def shutdown():
    runScheduler = False
    request.environ.get('werkzeug.server.shutdown')


57 58
# this needs to be uncommented in order for the scheduler to work
# but it's being weird cause it's hogging the thread
59 60
# runScheduler = True
# while runScheduler:
61 62
    # schedule.run_pending()
    # time.sleep(5)