__init__.py 1.11 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

13 14
# other imports
import redis
15 16
import schedule
import time
17 18

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

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


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

31

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

Landon DeCoito's avatar
Landon DeCoito committed
38

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

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