-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalexa2_edit.py
54 lines (47 loc) · 1.67 KB
/
alexa2_edit.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
#Generate Cricket news top 10 headlines from reddit
from flask import Flask
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/cric_news")
def get_headlines():
user_pass_dict = {'user': 'username',
'passwd': 'password',
'api_type': 'json'}
sess = requests.Session()
sess.headers.update({'User-Agent': 'Cric news'})
sess.post('https://www.reddit.com/api/login', data = user_pass_dict)
time.sleep(1)
url = 'https://www.reddit.com/r/Cricket/new/.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']]
titles = '... '.join([i for i in titles])
return titles
ti=get_headlines()
print(ti)
@app.route('/cric_news')
def homepage():
return get_headlines()
@ask.launch
def start_skill():
welcome_message = 'Hello there, would you like the cricket news?'
return question(welcome_message)
@ask.intent("YesIntent")
def share_headlines():
headlines = get_headlines()
headline_msg = 'The current cricket news headlines are {}'.format(headlines)
return statement(headline_msg)
@ask.intent("HelpIntent")
def no_intent():
help_text = 'Start by saying ...Alexa Ask cricket tops to start and answer with yes or no to continue...Would you like the cricket news?'
return question(help_text)
@ask.intent("NoIntent")
def no_intent():
bye_text = 'Too bad, but cricket is good though... bye'
return statement(bye_text)
if __name__ == '__main__':
app.run(debug=True)