-
Notifications
You must be signed in to change notification settings - Fork 981
Add new feature for latest news #147
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
Add new feature for latest news #147
Conversation
|
@harshitdx29 The overall structure looks good! We would need to add attribution also, right? |
swapagarwal
left a comment
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.
One of my quickest reviews! Awesome work, man. 😄
modules/src/news.py
Outdated
| import requests | ||
| import config | ||
| import os | ||
| import json |
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.
required?
modules/src/news.py
Outdated
|
|
||
| NEWS_API_KEY = os.environ.get('NEWS_API_KEY', config.NEWS_API_KEY) | ||
|
|
||
| def process(input, entities): |
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.
Since we are not using entities, we can initialize it to None to signify that.
modules/src/news.py
Outdated
| try: | ||
| r = requests.get('https://newsapi.org/v1/articles?source=' + source + '&apiKey=' + NEWS_API_KEY) | ||
| data = r.json() | ||
| assert(len(data["articles"])>0) |
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.
spacing around >
modules/src/news.py
Outdated
| title = article['title'] | ||
| description = article['description'] | ||
| url = article['url'] | ||
| template.add_element(title= title, item_url= url, description= description) |
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.
remove extra space after =
modules/src/news.py
Outdated
| error_message += '\nPlease ask me something else, like:' | ||
| error_message += '\n - latest news' | ||
| error_message += '\n - world news' | ||
| error_message += '\n - news' |
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.
align - with above lines
templates/generic.py
Outdated
| BUTTON_TITLE_CHARACTER_LIMIT = 20 | ||
| BUTTON_LIMIT = 3 | ||
| ELEMENTS_LIMIT = 10 | ||
| DESCRIPTION_CHARACTER_LIMIT = 160 |
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.
source?
templates/generic.py
Outdated
| def add_element(self, title='', description='', item_url='', image_url='', subtitle='', buttons=[]): | ||
| element = {} | ||
| element['title'] = title[:TITLE_CHARACTER_LIMIT] | ||
| element['description'] = description[:DESCRIPTION_CHARACTER_LIMIT] |
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.
Need to check if messenger supports this.
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.
My Understanding was that GenericTemplate is something we have written as a wrapper for formatting the output we are generating for each module. Can you please tell me about it?
Also, I din't understand the meaning of adding attribution.
Would be great if you could please help with the above doubts :)
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.
So, messenger has some templates that it supports. I've created classes mapping those so that you only have to create a object with the required data, and the rest is taken care of (formatting the data as you see while interacting with the bot). The Generic Template is here: https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template
As we are using third-party APIs for data, most of them are free to use but require us to add something like 'Powered by NewsAPI'. This check ensures that it's not our data to show, and we're just serving the data. This helps them gain audience. See the book / weather modules for reference.
|
Review changes done:
|
|
Good to go ? 😆 |
|
Thanks @harshitdx29! 👍 |
|
Thanks @swapagarwal 👍 Should i update the README for features in a separate PR? |
|
I have some backlog in README updation which I plan to do on weekend. 😇 |
News bot for handling requests of type:
-latest news
-news
-world news