This repository has been archived by the owner on Jul 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alexa-british-problems.py
65 lines (48 loc) · 1.78 KB
/
alexa-british-problems.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
import json
import time
import requests
import unidecode
from flask import Flask
from flask_ask import Ask, question, session, statement
APP = Flask(__name__)
ASK = Ask(APP, "/british_problems")
def get_british_problems():
"""Get the titles of the /r/britishproblems posts"""
user_pass_dict = {'user': 'alexabritishproblems',
'passwd': '83O9ls8eC77lmO%3@rw&',
'api_type': 'json'}
sess = requests.Session()
sess.headers.update(
{'User-Agent': 'alexa:british_problems:0.1 ' +
'(by /u/alexabritishproblems)'})
sess.post('https://wwww.reddit.com/api/login', data=user_pass_dict)
time.sleep(1)
url = "https://reddit.com/r/britishproblems/.json?limit=10"
html = sess.get(url)
data = json.loads(html.content.decode('utf-8'))
titles = [unidecode.unidecode(listing['data']['title'])
for listing in data['data']['children']]
return titles
titles = get_british_problems()
print titles
@APP.route('/')
def homepage():
"""Flask default routing"""
return 'greetz fren'
@ASK.launch
def start_skill():
"""Entry point for the alexa skill"""
welcome_message = 'Hello there, would you like to hear a very British problem?'
return question(welcome_message)
@ASK.intent("GetNewBritishProblem")
def handle_get_problem_intent():
"""Handles the intent for getting a new british problem and outputting it to Alexa"""
british_problem = get_british_problems()
return statement(british_problem)
@ASK.intent("NoIntent")
def handle_no_intent():
"""Handles an unmatched intent"""
goodbye_message = 'See you later... bye.'
return statement(goodbye_message)
if __name__ == '__main__':
APP.run(debug=True)