-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapplication.py
54 lines (37 loc) · 1.26 KB
/
application.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask
from flask_restful import Resource, Api, reqparse
from flask_cors import CORS
import logging
from sdgFinder import SDGFinder
app = Flask(__name__)
CORS(app)
api = Api(app)
# Require a parser to parse our POST request.
parser = reqparse.RequestParser()
parser.add_argument("query")
sdg = SDGFinder()
file = open("index_html", "r")
hello_ht = file.read()
file.close()
# logging.basicConfig(filename="Usage.log", level=logging.DEBUG, format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s")
@app.route("/")
def hello():
# app.logger.info('View Website')
return hello_ht
class Search(Resource):
def post(self):
# app.logger.info('Use basic search')
args = parser.parse_args()
_result = sdg.getSDG(str(args["query"]), detailed=False)
return _result
api.add_resource(Search, "/search")
class SearchDet(Resource):
def post(self):
# app.logger.info('use advanced search')
args = parser.parse_args()
_result = sdg.getSDG(str(args["query"]), detailed=True)
return _result
api.add_resource(SearchDet, "/detailed_search")
if __name__ == "__main__":
# logging.basicConfig(filename='usage.log',level=logging.DEBUG)
app.run(host='0.0.0.0', port=5000, debug=True)