-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
113 lines (84 loc) · 4.26 KB
/
main.py
File metadata and controls
113 lines (84 loc) · 4.26 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from flask import Flask
from ask_sdk_core.skill_builder import SkillBuilder
from flask_ask_sdk.skill_adapter import SkillAdapter
from ask_sdk_core.utils import is_request_type, is_intent_name, get_slot_value
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
from ask_sdk_model.ui import SimpleCard
import string
import MicroConnect
sb = SkillBuilder()
# Register all handlers, interceptors etc.
# For eg : sb.add_request_handler(LaunchRequestHandler())
@sb.request_handler(can_handle_func=is_request_type("LaunchRequest"))
def launch_request_handler(handler_input):
# type: (HandlerInput) -> Response
speech_text = "Welcome to MicroStrategy World 2020"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("World 2020", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response
@sb.request_handler(
can_handle_func=lambda handler_input :
is_intent_name("AMAZON.CancelIntent")(handler_input) or
is_intent_name("AMAZON.StopIntent")(handler_input))
def cancel_and_stop_intent_handler(handler_input):
# type: (HandlerInput) -> Response
speech_text = "Goodbye!"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("World 2020", speech_text))
return handler_input.response_builder.response
@sb.request_handler(can_handle_func=is_intent_name("GetValuefromMicroStrategy"))
def getValue_intent_handler(handler_input):
# type: (HandlerInput) -> Response
metric = get_slot_value(handler_input=handler_input, slot_name="Metric")
#por_ahora(handler_input)
if metric:
metric = string.capwords(metric)
value, valuePM = MicroConnect.getAnswer (metric)
percentageChange = (value/valuePM)-1
if percentageChange > 0:
delta = "increase"
else:
delta = "decrease"
speech_text = "The value for " + str(metric) + " is <say-as interpret-as='cardinal'>" + "{:.0f}".format(value) + "</say-as>$ that's a " + "{:.0%}".format(percentageChange) + " " + str(delta) + " compared to last month <say-as interpret-as='cardinal'> " + "{:.0f}".format(valuePM) + "</say-as>$ "
written_text = "The value for " + str(metric) + " is " + "{:,.0f}".format(value) + "$ that's a " + "{:,.0%}".format(percentageChange) + " " + str(delta) + " compared to last month " + "{:,.0f}".format(valuePM) + "$ "
else:
speech_text = "I'm sorry, I din't get the metric. Please try again"
written_text = speech_text
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("World 2020", written_text)).set_should_end_session(
False)
return handler_input.response_builder.response
@sb.request_handler(can_handle_func=is_intent_name("AMAZON.HelpIntent"))
def help_intent_handler(handler_input):
# type: (HandlerInput) -> Response
speech_text = "You can ask me for any of your business metrics. For example, try asking me for, What's the profit?"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("World 2020", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response
@sb.request_handler(can_handle_func=is_intent_name("AMAZON.FallbackIntent"))
def fallback_intent_handler(handler_input):
# type: (HandlerInput) -> Response
speech = "Sorry, I'm not sure of what you want. Can you please say it again?"
handler_input.response_builder.speak(speech).ask(speech).set_should_end_session(
False)
return handler_input.response_builder.response
@sb.exception_handler(can_handle_func=lambda i, e: True)
def all_exception_handler(handler_input, exception):
# type: (HandlerInput, Exception) -> Response
# Log the exception in CloudWatch Logs
print(exception)
speech = "Sorry, I didn't get it. Can you please say it again?"
handler_input.response_builder.speak(speech).ask(speech)
return handler_input.response_builder.response
app = Flask(__name__)
skill_response = SkillAdapter(
skill=sb.create(), skill_id="AMAZON SKILL ID GOES HERE", app=app)
skill_response.register(app=app, route="/")
@app.route("/")
def invoke_skill():
return skill_response.dispatch_request()
if __name__ == '__main__':
app.run()