forked from cfeitong/chat-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·63 lines (44 loc) · 1.27 KB
/
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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from gevent.wsgi import WSGIServer
from flask import Flask, redirect, render_template, request, url_for
from flask_restful import Api
from db import db
from question import sess
from resource import Ask, QAEntry, QAList
import json
app = Flask(__name__)
api = Api(app)
@app.route('/')
def root():
return redirect("qaform")
@app.route("/qaform")
def qaform():
return render_template('QAForm.html')
@app.route('/submit_question', methods=['POST'])
def submit_question():
form = request.form
question = form['question']
answer = form['answer']
date = form['date']
tags = form['tags'].split(' ')
db.insert(question, answer, date, tags)
db.commit()
return redirect(url_for("qaform"))
@app.route("/login", methods=["GET"])
def login():
return json.dumps({"userid": sess.apply_id()})
@app.route("/logout", methods=["GET"])
def logout():
args = request.args
userid = args.get("userid", None)
if userid is None:
return "", 401
sess.delete_id(userid)
return "", 200
api.add_resource(QAList, '/qalist')
api.add_resource(QAEntry, '/qalist/<int:id_>')
api.add_resource(Ask, '/ask')
if __name__ == "__main__":
server = WSGIServer(('', 5000), app)
server.serve_forever()