Ejemplo n.º 1
0
def SendStatement():

    sentence = request.form['sentence']
    response = {'success': True, 'processedSentence': None}

    # try:
    #     body = request.get_json() or dict()
    # except:
    #     body = dict()
    # sentence = body.get('sentence')
    # if not sentence:
    #     response['success'] = False
    #     LOGGER.error("Wrong key provided")
    #     # return jsonify(response)
    #     return render_template("public/response_sentence.html", page_body=response)
    try:
        processed_sentence = Monitors.Monitor_InputSentence(sentence)
        processed_sentence = processSentence(processed_sentence)
    except Exception as e:
        print(e.stack)
        response['success'] = False
        LOGGER.error("Failed to process sentence")
        # return jsonify(response)
        return render_template("public/response_sentence.html",
                               page_body=response)

    response['processedSentence'] = str(processed_sentence)
    LOGGER.info("request successfully processed")
    # return jsonify(response)
    print(response)
    return render_template("public/response_sentence.html",
                           page_body="Generated sentence is: {}".format(
                               response['processedSentence']))
Ejemplo n.º 2
0
 def wrapper(*args, **kwargs):
     authentication_token = request.form.get('AuthorizationToken')
     if authentication_token == AUTHORIZATION_TOKEN_EXPECTED:
         LOGGER.info("Successful auth")
         return _function(*args, **kwargs)
     else:
         LOGGER.error(
             "Failed auth with token {}".format(authentication_token))
         return render_template(
             "public/insert_sentence.html"
         ), requests.status_codes.codes['unauthorized']
Ejemplo n.º 3
0
    def create_connection(self):
        try:
            return psycopg2.connect(user=self.user,
                                    password=self.password,
                                    database=self.database,
                                    host=self.host,
                                    port=self.port)
        except (Exception, psycopg2.Error) as error:

            LOGGER.error(
                "Error while connecting to PostgreSQL with error: {}".format(
                    str(error)))
            return None