This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
57 lines (46 loc) · 1.65 KB
/
app.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
57
import os
from flask import Flask, render_template, request
from flask_ask import Ask, statement, question, session
import requests, json
app = Flask(__name__)
ask = Ask(app, '/')
headers = {'User-Agent': 'Alexa Skill'}
@ask.launch
def launched():
return question('Welcome to Open Benches. What would you like to know?')
@ask.intent("AMAZON.HelpIntent")
def help():
return question("You can ask for the latest bench, or for a random bench, or find out how many benches there are.")
@ask.intent("AMAZON.FallbackIntent")
def fallback():
return question("You can ask for the latest bench, or for a random bench, or find out how many benches there are.")
@ask.intent("LatestBench")
def latest_bench():
r = requests.get('https://openbenches.org/api/v1.0/alexa.json/?format=raw&latest', headers=headers)
r.encoding='utf-8-sig'
j = json.loads(r.text)
s = j["speech"]
return statement(s)
@ask.intent("RandomBench")
def random_bench():
r = requests.get('https://openbenches.org/api/v1.0/alexa.json/?format=raw&random', headers=headers)
r.encoding='utf-8-sig'
j = json.loads(r.text)
s = j["speech"]
return statement(s)
@ask.intent("HowMany")
def count_bench():
r = requests.get('https://openbenches.org/api/v1.0/alexa.json/?format=raw&count', headers=headers)
r.encoding='utf-8-sig'
j = json.loads(r.text)
s = j["speech"]
return statement(s)
@ask.intent("AMAZON.StopIntent")
def stop():
return statement("Have a nice day!")
@ask.intent("AMAZON.CancelIntent")
def stop():
return statement("Bye-bye!")
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)