-
Notifications
You must be signed in to change notification settings - Fork 21
/
app.py
36 lines (29 loc) · 848 Bytes
/
app.py
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
from flask import Flask, render_template, request
from search import searchData
import json, os
minorFileName = 'minor.json'
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/search/')
def search():
query = request.args.get('term')
results = searchData(query)
return json.dumps( [ course['Name'] for course in results ] )
@app.route('/ajax/', methods=['POST'])
def getCourse():
query = request.form.get('query')
results = searchData(query)
if results:
return json.dumps( results[0] )
else:
return json.dumps( {} )
@app.route('/minor/')
def minor():
with app.open_resource(minorFileName, 'r') as minorFile:
data = json.load(minorFile)
return json.dumps( data )
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port, debug=True)