コード例 #1
0
def lambda_handler(event, context):
    bot = skype_chatbot.SkypeBot(os.environ['app_id'],
                                 os.environ['app_secret'])
    time.sleep(0.25)
    data = event['data']
    bot_id = data['recipient']['id']
    bot_name = data['recipient']['name']
    recipient = data['from']
    service = data['serviceUrl']
    sender = data['conversation']['id']
    data['text'] = data['text'].replace(u'\xa0', u' ')
    coin = data['text'].split(' ')[1]
    price = get_price(coin.lower())
    print_me = f'Top 5 markets sorted by volume for {coin.upper()}\n'
    for price_info in price:
        print_me += str(price_info)
    bot.send_message(bot_id, bot_name, recipient, service, sender, print_me)
コード例 #2
0
import json
from prediction import Prediction
from train import Train
from flask import Flask, request
from upload_file import upload_file

app = Flask(__name__, static_url_path='/static')
#app_id = os.environ.get('APP_ID')
app_id = 'a1bd8198-255c-47f4-b259-f03e71b7eb5d'
#app_secret = os.environ.get('APP_SECRET')
app_secret = '[email protected]=K9JyrQd0w1zlWPMON1'
MODEL_DIR = os.environ.get('MODEL_DIR')
intents_file = "intents.json"
ml_prediction = None

bot = skype_chatbot.SkypeBot(app_id, app_secret)


@app.route("/")
def hello():
    return app.send_static_file('train.html')


@app.route('/api/messages', methods=['POST', 'GET'])
def webhook():
    try:
        ml_prediction
    except NameError:
        ml_prediction = Prediction(MODEL_DIR)
        ml_prediction.load_model()
    answer = ''