-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
91 lines (70 loc) · 2.44 KB
/
server.py
File metadata and controls
91 lines (70 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from flask import Flask, render_template, request, jsonify
import os
import json
import apis
from datetime import date
app = Flask(__name__)
schedule = apis.Scheduling(app_id='983c5cd2-3cc1-4cd4-91d1-64a1404f6eea',
app_secret_key='NYdwCIRZ3U1qt89PIxNnq89kCYjYygZagWgugJgA8XylomsFgOKrvvD2')
# Don't interfere with AngularJS
app.jinja_env.variable_start_string = '{|'
app.jinja_env.variable_end_string = '|}'
# HomePage
@app.route('/')
def index():
return render_template('index.html')
users = {}
# User save data
@app.route('/user/<username>', methods = ['GET', 'PUT'])
def user(username):
if request.method == 'GET':
return jsonify(users[username])
if request.method == 'PUT':
users[username] = request.json
return jsonify(users[username])
YEAR = date.today().year % 100;
NEITHER = '0';
BOTH = '1';
FALL_ONLY = 'F' + str(YEAR);
SPRING_ONLY = 'S' + str(YEAR);
FALLVALS = {};
SPRINGVALS = {};
@app.route('/fall/<int:course>', methods = ['GET'])
def getFallCourse(course):
if request.method == 'GET':
if (course in FALLVALS):
return jsonify(FALLVALS[course])
fallval = schedule.course(semester=FALL_ONLY, course_number=course)
if (fallval):
FALLVALS[course] = fallval
return jsonify(fallval)
@app.route('/spring/<int:course>', methods = ['GET'])
def getSpringCourse(course):
if request.method == 'GET':
if course in SPRINGVALS:
return jsonify(SPRINGVALS[course])
springval = schedule.course(semester=SPRING_ONLY, course_number=course)
if (springval):
SPRINGVALS[course] = springval
return jsonify(springval)
PREREQS = json.load(open('static/PREREQS.json'))
@app.route('/prereqs', methods = ['GET'])
def get_prereqs():
if request.method == 'GET':
return jsonify(PREREQS)
SCS_CS_MAJOR = json.load(open('static/SCS_CS_MAJOR.json'))
MAJORS = {"SCS_CS_M": SCS_CS_MAJOR}
with open('static/MAJORS.json', 'w') as f:
json.dump(MAJORS, f)
@app.route('/majors', methods = ['GET'])
def get_majors():
if request.method == 'GET':
return jsonify({'Majors': MAJORS})
@app.route('/majors/<major>', methods = ['GET'])
def get_major(major):
if request.method == 'GET':
return jsonify(MAJORS["SCS_CS_M"])
if __name__ == "__main__":
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)