-
Notifications
You must be signed in to change notification settings - Fork 0
/
AskBuzz.py
219 lines (158 loc) · 5.51 KB
/
AskBuzz.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import logging
import requests
from flask import Flask, render_template
from flask_ask import Ask, statement, audio, context, session
from utils import buses, dining, tweets, tv, rss, tech_scraper
app = Flask(__name__)
ask = Ask(app, "/")
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
def get_alexa_location():
url = "https://api.amazonalexa.com/v1/devices/{}/settings/address".format(context.System.device.deviceId)
consent = context.System.user.permissions.consentToken
header = {'Accept': 'application/json',
'Authorization': 'Bearer {}'.format(consent)}
r = requests.get(url, headers=header)
if r.status_code == 200:
j = r.json()
addr = "{l1}, {city}, {state} {postal}".format(l1=j['addressLine1'], city=j['city'], state=j['stateOrRegion'],
postal=j['postalCode'])
return addr
def get_login():
user = session.user['accessToken']
split = user.split(',')
username = split[0]
password = split[1]
return [username, password]
@ask.intent("GoodWord")
def good_word():
gw = render_template('GoodWord')
return statement(gw)
@ask.intent("WhiteGold")
def white_gold():
wg = render_template('WhiteGold')
return statement(wg)
@ask.intent("RamblinWreck")
def rambin_wreck():
rw = render_template('RamblinWreck')
return statement(rw)
@ask.intent("AlmaMater")
def alma_mater():
am = render_template('AlmaMater')
return statement(am)
@ask.intent("GeorgePBurdell")
def george_burdell():
gp = render_template('GeorgePBurdell')
return statement(gp)
@ask.intent("MyClasses")
def good_word():
return statement(tech_scraper.get_str_from_file("Classes"))
@ask.intent("Setup")
def setup():
myfile = open("data.txt", "w")
myfile.write("")
myfile.close()
user, passw = get_login()
print("Logging in")
tech_scraper.login(user, passw)
print("Setting up Classes")
tech_scraper.get_classes()
print("Setting up Meal Swipes")
tech_scraper.get_meal_swipes()
print("Setting up Dining Dollars")
tech_scraper.get_dining_dollars()
print("Setting up Buzz Funds")
tech_scraper.get_buzz_funds()
print("Set up")
return statement("I'm Ready to make it work!")
@ask.intent("MyMealSwipes")
def good_word():
return statement(tech_scraper.get_str_from_file("MealSwipes"))
@ask.intent("MyDiningDollars")
def good_word():
return statement(tech_scraper.get_str_from_file("DiningDollars"))
@ask.intent("MyBuzzFunds")
def good_word():
return statement(tech_scraper.get_str_from_file("BuzzFunds"))
@ask.intent("AllDiningOpen")
def dining_opens():
return statement(dining.dining_open())
@ask.intent("GetNews")
def get_news():
news = rss.get_news(4)
msg = render_template('News', news=news)
return statement(msg)
@ask.intent("GetEvents")
def get_events():
events = rss.get_events(5)
msg = render_template('Events', events=events)
return statement(msg)
@ask.intent("DiningHallOpen")
def dining_hall_open(hall=None):
if hall is None:
return statement("Please specify a dining hall.")
if hall.lower() == "north avenue":
return statement(dining.is_open("north ave")[1])
if hall.lower() == "britian":
return statement(dining.is_open("brittain")[1])
return statement(dining.is_open(hall.lower())[1])
@ask.intent("DiningHallHours")
def dining_hall_hours(hall=None):
if hall is None:
return statement("Please specify a dining hall.")
if hall.lower() == "north avenue":
return statement(dining.dining_hours("north ave"))
if hall.lower() == "britian":
return statement(dining.dining_hours("brittain"))
return statement(dining.dining_hours(hall.lower()))
@ask.intent("ClassAvg")
def get_class_avg(classname):
return statement(dining.course_critique(classname))
@ask.intent("NextBus")
def next_bus(col=None):
if col is None:
return statement("Please specify a bus route.")
echo_location = get_alexa_location()
u = buses.User(echo_location)
nxt = buses.sort_stops(u.lat, u.lng, col.lower())
return statement(nxt)
@ask.intent("TwitterUpdates")
def twit():
twts = tweets.get_tweets('GeorgiaTech', 3)
msg = render_template('Tweets', tweets=twts)
return statement(msg)
@ask.intent('WREKRadio')
def wrek_radio():
speech = "Tuning to Wreck Radio"
stream_url = "https://gist.githubusercontent.com/Josh-McFarlin/b8811e0e93f5d9e3e37e57a56f86987b/raw/b2b201733b1acbfd65c3005cffd76fa12b4cea1f/WREKRadio.m3u"
return audio(speech).play(stream_url)
@ask.intent('GTPD')
def gtpd():
msg = render_template('GTPD')
return statement(msg)
@ask.intent('TwitterUpdates')
def twit():
twts = tweets.get_tweets('GeorgiaTech', 3)
msg = render_template('Tweets', tweets=twts)
return statement(msg)
@ask.intent('GetChannel')
def channel(chaname):
tv_channel = tv.find_channel(chaname)
if tv_channel:
msg = "{name} is on channel {num}.".format(name=chaname, num=tv_channel)
else:
msg = "Sorry, this channel is not available."
return statement(msg)
@ask.intent('Smoke')
def stop():
return statement("Baasim Rehan is smoking it up.")
@ask.intent('AMAZON.PauseIntent')
def pause():
return audio('Pausing WRECK Radio.').stop()
@ask.intent('AMAZON.ResumeIntent')
def resume():
return audio('Resuming WRECK Radio.').resume()
@ask.intent('AMAZON.StopIntent')
def stop():
return audio('Stopping WRECK Radio.').clear_queue(stop=True)
if __name__ == '__main__':
app.run(debug=True)