-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
56 lines (43 loc) · 1.5 KB
/
app.py
File metadata and controls
56 lines (43 loc) · 1.5 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging, os, sys, config
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
from coinmarketcap import Market
coinmarketcap = Market()
reload(sys)
crypto = config.crypto
sys.setdefaultencoding('utf8')
app = Flask(__name__)
ask = Ask(app, "/")
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
quitkeywords = ['quit', 'exit', 'cancel', 'leave']
@ask.launch
def start():
print "here"
welcome_msg = render_template('welcome', crypto = crypto)
return question(welcome_msg)
@ask.intent("YesIntent", convert={'yon': str})
def menu(yon):
print yon
round_msg = render_template('round_msg', crypto = crypto)
help = render_template('help', crypto = crypto)
if yon == 'help':
print "here"
return question(help)
if yon in quitkeywords:
return statement("")
return question(round_msg)
@ask.intent("AnswerIntent")
def response():
price = coinmarketcap.ticker(crypto, limit=1)
price = price[0]
price = str(price["price_usd"])
priceresponse = render_template('priceresponse', crypto = crypto , price = price)
return statement(priceresponse) \
.simple_card(title=crypto.title()+' Price', content="The " + crypto + " price is " + price + " dollars")
@ask.session_ended
def session_ended():
return statement("")
if __name__ == "__main__":
app.run(debug=True)