-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new feature for latest news * Adding main module and test module * Bug Fixes related to search query * Review changes
- Loading branch information
1 parent
c5fb166
commit 59beb1c
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
'joke', | ||
'movie', | ||
'music', | ||
'news', | ||
'quote', | ||
'request', | ||
'time', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import requests | ||
import config | ||
import os | ||
from templates.generic import * | ||
from templates.text import TextTemplate | ||
|
||
NEWS_API_KEY = os.environ.get('NEWS_API_KEY', config.NEWS_API_KEY) | ||
|
||
def process(input, entities=None): | ||
output = {} | ||
source = 'google-news' | ||
try: | ||
r = requests.get('https://newsapi.org/v1/articles?source=' + source + '&apiKey=' + NEWS_API_KEY) | ||
data = r.json() | ||
assert(len(data["articles"]) > 0) | ||
template = GenericTemplate() | ||
for article in data['articles']: | ||
title = article['title'] | ||
description = article['description'] | ||
url = article['url'] | ||
buttons = ButtonTemplate() | ||
buttons.add_web_url('Powered by NewsAPI', 'https://newsapi.org/') | ||
template.add_element(title=title, item_url=url, subtitle=description, buttons=buttons.get_buttons()) | ||
output['input'] = input | ||
output['output'] = template.get_message() | ||
output['success'] = True | ||
except: | ||
error_message = 'I couldn\'t perform that action.' | ||
error_message += '\nPlease ask me something else, like:' | ||
error_message += '\n - latest news' | ||
error_message += '\n - world news' | ||
error_message += '\n - news' | ||
output['error_msg'] = TextTemplate(error_message).get_message() | ||
output['success'] = False | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import modules | ||
|
||
def test_news(): | ||
assert('news' == modules.process_query('news')[0]) | ||
assert('news' == modules.process_query('latest news')[0]) | ||
assert('news' == modules.process_query('world news')[0]) | ||
assert('news' != modules.process_query('something random')[0]) |