forked from azk0019/CourseProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
64 lines (48 loc) · 1.27 KB
/
server.py
File metadata and controls
64 lines (48 loc) · 1.27 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
from flask import Flask, json, request
# TODO
# import NainaSearchModule
dummy_json_results = {'results' : [{'docNumber' : 1,'body' : 'if you look at the two Unigram Language Models...', 'timestamp' : '12:24:01', 'week' : 7, 'lecture' : '7.2'}]}
api = Flask(__name__)
'''
Basic endpoint to check if the server is alive
'''
@api.route('/', methods=['GET', 'POST'])
def is_alive():
return "yes, the server is alive; <br>hit /test for json response <br>or POST a JSON query to /search"
'''
Returns a dummy JSON result
'''
@api.route('/test', methods=['GET'])
def test():
return json.dumps(dummy_json_results)
'''
POST endpoint to ingest JSON queries of the form:
{
"query": [
"query",
"terms"
]
}
returns results as JSON in the form:
{
"results": [
{
"docID": 1,
"body": "if you look at the two Unigram Language Models...",
"timestamp": "12:24:01",
"week": 7,
"lecture": "7.2"
}
]
}
'''
@api.route('/search', methods=['POST'])
def search():
print(request.get_json())
# TODO
# pass JSON query to search function
# results_json = naina_search(request.get_json())
# return json.dumps(results_json)
return json.dumps(dummy_json_results)
if __name__ == '__main__':
api.run('localhost')