-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspacegeek.py
56 lines (39 loc) · 1.33 KB
/
spacegeek.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import logging
import os
from random import randint
from flask import Flask, render_template
from flask_ask import Ask, request, session, question, statement
app = Flask(__name__)
ask = Ask(app, "/")
logging.getLogger('flask_ask').setLevel(logging.DEBUG)
@ask.launch
def launch():
return get_new_fact()
@ask.intent('GetNewFactIntent')
def get_new_fact():
num_facts = 13 # increment this when adding a new fact template
fact_index = randint(0, num_facts-1)
fact_text = render_template('space_fact_{}'.format(fact_index))
card_title = render_template('card_title')
return statement(fact_text).simple_card(card_title, fact_text)
@ask.intent('AMAZON.HelpIntent')
def help():
help_text = render_template('help')
return question(help_text).reprompt(help_text)
@ask.intent('AMAZON.StopIntent')
def stop():
bye_text = render_template('bye')
return statement(bye_text)
@ask.intent('AMAZON.CancelIntent')
def cancel():
bye_text = render_template('bye')
return statement(bye_text)
@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
app.run(host='0.0.0.0',debug=True)