这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
WIT_AI_ACCESS_TOKEN = 'IKJJJYYVR3X672DHFVS7U7C4L2MQSS2P'
GOODREADS_ACCESS_TOKEN = '<GOODREADS_ACCESS_TOKEN>'
WORDS_API_KEY = '<WORDS_API_KEY>'
NYT_API_KEY = '<NYT_ARTICLES_API_KEY>'
JOKES_SOURCE_FILE = 'data/jokes.json'
1 change: 1 addition & 0 deletions data/jokes.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need

"jokes": [
"What happens to a frog's car when it breaks down?\nIt gets toad away.",
"Why was six scared of seven?\nBecause seven \"ate\" nine.",
Expand Down
1 change: 1 addition & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'help',
'joke',
'movie',
'news',
'quote',
'request',
'wiki',
Expand Down
4 changes: 3 additions & 1 deletion modules/src/anime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def process(input, entities):

template = TextTemplate()
template.set_text('Title: ' + data[0]['title'] + '\nSynopsis: ' + data[0]['synopsis'])
template.set_post_text('\nCommunity Rating: ' + str(data[0]['community_rating']) + '\nStatus: ' + data[0]['status'])
#only want to see 2 decimal places
rating = {0:.2f}.format(data[0]['community_rating'])
template.set_post_text('\nCommunity Rating: ' + str(rating) + '\nStatus: ' + data[0]['status'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this goes in separate PR

text = template.get_text()

template = ButtonTemplate(text)
Expand Down
30 changes: 30 additions & 0 deletions modules/src/news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import config
import requests
import json
from templates.generic import GenericTemplate

NYT_API_KEY = os.environ.get('NYT_API_KEY', config.NYT_API_KEY)

def process(input, entities):
output = {}
try:
topic = str(entities['news'][0]['value'])
api_response = requests.get(url='https://api.nytimes.com/svc/search/v2/articlesearch.json', params={'api-key': NYT_API_KEY, 'q': topic})
news_dict = json.loads(api_response.text)
news = news_dict['response'].get('docs')
template = GenericTemplate()
if news:
for i in range(0,min(2,len(news))):
title = news[i].get('headline').get('main')
item_url = news[i].get('web_url')
image_url = news[i].get('multimedia')[0].get('url') if len(news.get('multimedia')) >= 1 else None
subtitle = news[i].get('snippet')
buttons = [ {'title': "Data provided by The New York Times", 'url':item_url} ]
template.add_element(title=title, item_url=item_url, image_url=image_url, subtitle=subtitle, buttons=buttons)
output['input'] = input
output['output'] = template.get_message()
output['success'] = True
except:
output['success'] = False
return output
7 changes: 7 additions & 0 deletions modules/tests/test_news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import modules

def test_news():
assert('news' == modules.process_query("what's the latest on the facebook case")[0])
assert('news' == modules.process_query("What's happening around the world")[0])
assert('news' == modules.process_query("What's the latest on fashion news")[0])
assert('news' != modules.process_query("something random")[0])