Alexa-news-stentiment-evalu.../f-ask/samples/reddit/main.py

62 lines
1.6 KiB
Python
Raw Normal View History

2019-04-12 20:08:36 +00:00
import logging
import os
from flask import Flask
from flask_ask import Ask, request, session, question, statement
2019-04-14 13:07:54 +00:00
import random
import yaml
2019-04-12 20:08:36 +00:00
app = Flask(__name__)
ask = Ask(app, "/")
logging.getLogger('flask_ask').setLevel(logging.DEBUG)
@ask.launch
def launch():
2019-04-15 19:23:08 +00:00
return question("Each excercise will take about 5 minutes. Are you Ready?")
2019-04-12 20:08:36 +00:00
2019-04-14 13:07:54 +00:00
def get_workoutplan():
2019-04-15 19:23:08 +00:00
with open("C:/Users/John/Desktop/GST/samples/reddit/workouts.yaml", 'r') as stream:
2019-04-14 13:07:54 +00:00
exercises = yaml.load(stream)
exercise_names = random.sample(list(exercises), 5)
workout_plan = []
for exercise_name in exercise_names:
exercise = str(exercises[exercise_name]["duration"][0]) + " " + str(exercises[exercise_name]["duration"][1] )+ " of " + exercise_name
workout_plan.append(exercise)
return workout_plan
2019-04-12 20:08:36 +00:00
2019-04-15 19:23:08 +00:00
@ask.intent('YesIntent', mapping={'part': 'Part'})
def start_workout(part):
print(part)
2019-04-14 13:07:54 +00:00
workout_plan = get_workoutplan()
2019-04-15 19:23:08 +00:00
response = "Do "
2019-04-14 13:07:54 +00:00
for excercise in workout_plan[:-1]:
response += excercise + ", "
response += " and " + workout_plan[-1]
2019-04-15 19:23:08 +00:00
print(response)
return statement(response)
2019-04-12 20:08:36 +00:00
@ask.intent('NoIntent')
def no():
2019-04-14 13:07:54 +00:00
return statement("Allright, maybe later.")
2019-04-12 20:08:36 +00:00
@ask.intent('AMAZON.HelpIntent')
def help():
2019-04-14 13:07:54 +00:00
speech_text = 'If you want a quick workout just say "workout"'
return statement(speech_text)
2019-04-12 20:08:36 +00:00
2019-04-15 19:23:08 +00:00
2019-04-12 20:08:36 +00:00
@ask.session_ended
def session_ended():
return "{}", 200
if __name__ == '__main__':
if 'ASK_VERIFY_REQUESTS' in os.environ:
verify = str(os.environ.get('ASK_VERIFY_REQUESTS', '')).lower()
if verify == 'false':
app.config['ASK_VERIFY_REQUESTS'] = False
2019-04-15 19:23:08 +00:00
app.run()