__init__.py 1.26 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
from parscript import load_data
8
from getconnectedscript import load_getconn_data
9 10
from redisactions import *
from appmethods import *
11 12

# python imports
13
import json
14

15 16
# other imports
import redis
17 18
import schedule
import time
19 20

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

23 24
# setting up redis database
redisdb = redis.from_url("redis://localhost:6379/0", db=0)
25

26 27 28 29 30
# setting up cacheing
schedule.every().day.at("02:00").do(updatebothdbs)
# schedule.every(5).seconds.do(updatebothdbs)


Landon DeCoito's avatar
Landon DeCoito committed
31 32
@app.route("/")
def display_default():
33
    resp = render_template('welcomepage.html')
34
    return resp
Landon DeCoito's avatar
Landon DeCoito committed
35

36

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

Landon DeCoito's avatar
Landon DeCoito committed
43

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

# 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)