Browse Source

daily commit

master
shihxuancheng 5 years ago
parent
commit
76f386cb1f
8 changed files with 68 additions and 23 deletions
  1. 3
      .gitignore
  2. 12
      back_end/bot_app/__init__.py
  3. 0
      back_end/bot_app/fulfillment/__init__.py
  4. 41
      back_end/bot_app/fulfillment/controllers.py
  5. 0
      back_end/bot_app/fulfillment/detect_intent_texts.py
  6. 0
      back_end/bot_app/fulfillment/equip_crawling.py
  7. 30
      back_end/config.py
  8. 5
      back_end/run.py

3
.gitignore

@ -1,4 +1,5 @@
.vscode/
.ipynb_checkpoints/
env/
credential
credential
__pycache__

12
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!!!'

0
back_end/bot_app/fulfillment/__init__.py

back_end/bot_app.py → 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()

back_end/detect_intent_texts.py → back_end/bot_app/fulfillment/detect_intent_texts.py

back_end/equip_crawling.py → back_end/bot_app/fulfillment/equip_crawling.py

30
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

5
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)
Loading…
Cancel
Save