-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpy2_reddit_app.py
More file actions
81 lines (60 loc) · 2.63 KB
/
Copy pathpy2_reddit_app.py
File metadata and controls
81 lines (60 loc) · 2.63 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
import logging
from flask import Flask
from flask_ask import Ask, statement, question, session
import reddit_play
import random
app = Flask(__name__)
ask = Ask(app, "/joke_search_for_reddit")
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
@ask.launch
def ask_joke_type():
welcome = "Welcome! What kind of joke would you like to hear?"
return question(welcome).reprompt('What kind of joke would you like?')
@ask.intent("JokeType")
def tell_joke(joke_type=None):
try:
if joke_type is None:
joke_type = 'funny'
jokehead, joke, joke_type = reddit_play.get_joke(joke_type)
msg = "I couldn't understand you, so instead I'll tell you one of my favorite jokes. "
else:
jokehead, joke, joke_type = reddit_play.get_joke(joke_type)
if joke_type in ['funny', 'dirty', 'dad']:
msg = 'Oh boy, here comes one of my favorite {} jokes.... '.format(joke_type)
else:
msg1 = 'Ok, get ready for a joke about {}..... '.format(joke_type)
msg2 = 'All right, here is one of my favorite jokes about {}..... '.format(joke_type)
msg3 = 'Ready or not, here comes a joke about {}..... '.format(joke_type)
msg = random.choice([msg1, msg2, msg3])
msg = msg + jokehead + '...' + joke
msg2 = msg.lower().replace('..', '.. ')\
.replace('http://','')\
.replace('https://','')\
return statement(msg2).simple_card('Joke Fairy', msg)
except Exception as e:
joke_type = 'funny'
jokehead, joke, joke_type = reddit_play.get_joke(joke_type)
msg = "I couldn't understand you, so instead I'll tell you a random funny joke. "
msg = msg + jokehead + '...' + joke
return statement(msg).simple_card('Joke Fairy', msg)
@ask.intent('AMAZON.HelpIntent')
def help():
speech_text = 'Joke fairy is an unofficial Reddit joke search app that ' +\
'will tell you a joke about whatever you like. ' +\
'For example, you can ask Joke fairy for a joke about Russia, ' +\
'or you can ask for a dirty joke, a funny joke, or a dad joke. What kind of joke would ' +\
'you like to hear?'
reprompt_text = 'What kind of joke would you like?'
return question(speech_text).reprompt(reprompt_text)
@ask.intent('AMAZON.StopIntent')
def stop():
msg = 'Smell you later!'
return statement(msg)
@ask.intent('AMAZON.CancelIntent')
def cancel():
msg = 'Smell you later!'
return statement(msg)
if __name__ == '__main__':
# print(ask_joke_type().__dict__)
print(tell_joke('dirty').__dict__)
# app.run(debug=True)