From 76f386cb1f3879fade98cd669345c5aa6d08c4d4 Mon Sep 17 00:00:00 2001 From: shihxuancheng Date: Tue, 17 Sep 2019 17:58:30 +0800 Subject: [PATCH] daily commit --- .gitignore | 3 +- back_end/bot_app/__init__.py | 12 ++++++ back_end/bot_app/fulfillment/__init__.py | 0 .../fulfillment/controllers.py} | 41 +++++++++---------- .../fulfillment}/detect_intent_texts.py | 0 .../fulfillment}/equip_crawling.py | 0 back_end/config.py | 30 ++++++++++++++ back_end/run.py | 5 +++ 8 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 back_end/bot_app/__init__.py create mode 100644 back_end/bot_app/fulfillment/__init__.py rename back_end/{bot_app.py => bot_app/fulfillment/controllers.py} (92%) rename back_end/{ => bot_app/fulfillment}/detect_intent_texts.py (100%) rename back_end/{ => bot_app/fulfillment}/equip_crawling.py (100%) create mode 100644 back_end/config.py create mode 100644 back_end/run.py diff --git a/.gitignore b/.gitignore index 4323aff..ef63112 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode/ .ipynb_checkpoints/ env/ -credential \ No newline at end of file +credential +__pycache__ \ No newline at end of file diff --git a/back_end/bot_app/__init__.py b/back_end/bot_app/__init__.py new file mode 100644 index 0000000..e13818e --- /dev/null +++ b/back_end/bot_app/__init__.py @@ -0,0 +1,12 @@ +from flask import Flask +from bot_app.fulfillment.controllers import fulfillment + +app = Flask(__name__) + +app.config.from_object('config') + +app.register_blueprint(fulfillment) + +@app.route('/') +def index(): + return 'Service Working!!!' \ No newline at end of file diff --git a/back_end/bot_app/fulfillment/__init__.py b/back_end/bot_app/fulfillment/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/back_end/bot_app.py b/back_end/bot_app/fulfillment/controllers.py similarity index 92% rename from back_end/bot_app.py rename to back_end/bot_app/fulfillment/controllers.py index 4494f8a..9997f5d 100644 --- a/back_end/bot_app.py +++ b/back_end/bot_app/fulfillment/controllers.py @@ -1,21 +1,29 @@ import os -from flask import Flask, jsonify, request, json +from flask import Blueprint, Flask, jsonify, request, json import threading import time import requests from queue import Queue -app = Flask(__name__) +# app = Flask(__name__) +fulfillment = Blueprint('fulfillment',__name__,url_prefix='/qa_bot/fulfillment') result = None -@app.route('/') -def sayHi(): - return 'Hello World!!!' +@fulfillment.route('/',methods=['GET', 'POST']) +def index(): + jsonObj = request.get_json() + try: + handleName = jsonObj.get('queryResult').get('intent')['displayName'] + print('Handler:', handleName) + return eval(handleName + '(jsonObj)') + except: + return sample_response('找不到對應的fulfillment handler!!!') -@app.route("/short_call", methods=['GET', 'POST']) + +@fulfillment.route("/short_call", methods=['GET', 'POST']) def five_secend_call(): global result result = None @@ -42,18 +50,6 @@ def fetch_url(): result = res return res - -@app.route('/qa_bot/fulfillment', methods=['GET', 'POST']) -def index(): - jsonObj = request.get_json() - try: - handleName = jsonObj.get('queryResult').get('intent')['displayName'] - print('Handler:', handleName) - - return eval(handleName + '(jsonObj)') - except: - return sample_response('找不到對應的fulfillment handler!!!') - # 確認訂單 def buying_drink_ordering_summary(fulfillment): context = lookup_context(fulfillment, 'buying_drink_ordering-followup') @@ -166,10 +162,11 @@ def lookup_context(fulfillment,lookup_pattern): return next((x for x in contexts if x['name']== search_key),None) def main(): - port = os.environ.get('FLASK_EXPOSE_PORT') - port = port if port != None else 8080 - app.config['JSON_AS_ASCII'] = False - app.run(host='0.0.0.0', port=port, debug=True) + pass + # port = os.environ.get('FLASK_EXPOSE_PORT') + # port = port if port != None else 8080 + # app.config['JSON_AS_ASCII'] = False + # app.run(host='0.0.0.0', port=port, debug=True) if __name__ == '__main__': main() diff --git a/back_end/detect_intent_texts.py b/back_end/bot_app/fulfillment/detect_intent_texts.py similarity index 100% rename from back_end/detect_intent_texts.py rename to back_end/bot_app/fulfillment/detect_intent_texts.py diff --git a/back_end/equip_crawling.py b/back_end/bot_app/fulfillment/equip_crawling.py similarity index 100% rename from back_end/equip_crawling.py rename to back_end/bot_app/fulfillment/equip_crawling.py diff --git a/back_end/config.py b/back_end/config.py new file mode 100644 index 0000000..63fc5fe --- /dev/null +++ b/back_end/config.py @@ -0,0 +1,30 @@ +import os + +# Statement for enabling the development environment +DEBUG = True + +# Define the application directory +BASE_DIR = os.path.abspath(os.path.dirname(__file__)) + +# Define the database - we are working with +# SQLite for this example +SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(BASE_DIR, 'app.db') +DATABASE_CONNECT_OPTIONS = {} + +# Application threads. A common general assumption is +# using 2 per available processor cores - to handle +# incoming requests using one and performing background +# operations using the other. +THREADS_PER_PAGE = 2 + +# Enable protection agains *Cross-site Request Forgery (CSRF)* +CSRF_ENABLED = True + +# Use a secure, unique and absolutely secret key for +# signing the data. +CSRF_SESSION_KEY = "secret" + +# Secret key for signing cookies +SECRET_KEY = "secret" + +JSON_AS_ASCII = False \ No newline at end of file diff --git a/back_end/run.py b/back_end/run.py new file mode 100644 index 0000000..29d1096 --- /dev/null +++ b/back_end/run.py @@ -0,0 +1,5 @@ +import os +from bot_app import app +port = os.environ.get('FLASK_EXPOSE_PORT') +port = port if port != None else 8080 +app.run(host='0.0.0.0', port=port, debug=True) \ No newline at end of file