__init__.py 1.23 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 appmethods import update_both_dbs, run_schedule_loop
8
from redisactions import redisdb
9 10

# python imports
11
import json
12
import thread
13

14 15
# other imports
import redis
16

17 18

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

21

Landon DeCoito's avatar
Landon DeCoito committed
22 23
@app.route("/")
def display_default():
24
    resp = render_template('welcomepage.html')
25
    return resp
Landon DeCoito's avatar
Landon DeCoito committed
26

27

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

Landon DeCoito's avatar
Landon DeCoito committed
34

35
@app.route("/api/getconnected")
36
def display_GC_data():
37
    resp = Response(redisdb.get("gcdict"))  # .encode('utf-8'))
38 39
    resp.headers['Content-Type'] = 'application/json; charset=utf-8'
    return resp
40

41

42
@app.route("/api/lastupdate")
43
def get_last_update():
44 45
    resp = Response(redisdb.lindex("dbupdatelog", 0).replace("\n", "</br>"))
    return resp
46 47


48
try:
49
    thread.start_new_thread(run_schedule_loop, ())
50 51 52 53 54
    print "started thread!"
except:
    print "===================================================" \
        + "Unable to start scheduling thread" \
        + "==================================================="