-
Notifications
You must be signed in to change notification settings - Fork 981
add news feature #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
add news feature #48
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9e1db51
add news feature
akornor 662b3fd
fixed bug in test_news
akornor 2bead5d
damn found it, final fix
akornor e5bd653
fuxkkkkkk
akornor b7c1892
Travis CI is wild !
akornor 6763bb0
smhhh
akornor a1cd053
might work
akornor 533e1dc
final change, this should work
akornor 7ea4bed
well,yeah
akornor 6db0d33
Update progress + feature requests
swapagarwal 08c7eff
anime: format rating to 2 decimal places
akornor 7ba45c3
sweet
akornor e5a6310
done
akornor 3f5a1a6
done
akornor c8d0aa8
merge
akornor ea02d31
Merge branch 'master' into news-feature
akornor 5567388
Merge branch 'news-feature' of https://github.com/badmon/JARVIS-on-Me…
akornor f48f0ee
Merge remote-tracking branch 'upstream/master' into news-feature
akornor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| 'help', | ||
| 'joke', | ||
| 'movie', | ||
| 'news', | ||
| 'quote', | ||
| 'request', | ||
| 'wiki', | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -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']) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this goes in separate PR |
||
| text = template.get_text() | ||
|
|
||
| template = ButtonTemplate(text) | ||
|
|
||
This file contains hidden or 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,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 |
This file contains hidden or 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("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]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need