Exemplo n.º 1
0
def autoRobotAnswer(id, question_model):
    pid = os.fork()
    if pid != 0:
        return
    url = "http://47.104.98.154:8080/anonymous/wordManage/wenda"
    headers = {'content-type': "application/json"}
    query_string = {"question": question_model.title, "robotid": "1791"}

    if (len(question_model.answers) < 1):

        response = requests.post(url, data=json.dumps(query_string), headers=headers)
        jstr = response.text
        # error : {"result":false,"message":"服务器处理异常!","data":null}
        print jstr
        if (jstr['message'] == 'success'):
            print jstr['message']
            question_id = id
            print question_id

            content = jstr['data']['answers']
            print content
            answer_model = AnswerModel(content=content)
            answer_model.author = 'robot'
            answer_model.question = question_model
            db.session.add(answer_model)
            db.session.commit()
Exemplo n.º 2
0
def comment():
    question_id = flask.request.form.get('question_id')
    content = flask.request.form.get('content')
    answer_model = AnswerModel(content=content)
    answer_model.author = flask.g.user
    answer_model.question = QuestionModel.query.get(question_id)
    db.session.add(answer_model)
    db.session.commit()
    return flask.redirect(flask.url_for('detail',id=question_id))
Exemplo n.º 3
0
def comment():
    question_id = flask.request.form.get('question_id')
    content = flask.request.form.get('content')
    answer_model = AnswerModel(content=content)
    answer_model.author = UserModel.query.filter_by(username='******').first()
    answer_model.question = QuestionModel.query.get(question_id)
    db.session.add(answer_model)
    db.session.commit()
    return flask.redirect(flask.url_for('detail',id=question_id))