Skip to content
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

My new feature(Financial News) #1090

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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 README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
This contribution adds a new feature to the bot which is displaying financial news/stock information or economic updates when given a query.
# JARVIS on Messenger

Just A Rather Very Intelligent System, now on Messenger!
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
TMDB_API_KEY = '<<TMDB_API_KEY>>'
WORDS_API_KEY = '<<WORDS_API_KEY>>'
YOUTUBE_DATA_API_KEY = '<<YOUTUBE_DATA_API_KEY>>'
FINANCIAL_API_KEY='62ac729f4e89e1.15279050'

# Local Testing
WIT_LOCAL_DATA = 'local/wit.json'
Expand Down
1 change: 1 addition & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'weather',
'wiki',
'xkcd',
'financial',
]

# List of modules that send data personalized to the user
Expand Down
35 changes: 35 additions & 0 deletions modules/src/financial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import requests
from termcolor import colored as cl
import config
from templates.generic import *
from templates.text import TextTemplate

#api_key = '62ac729f4e89e1.15279050 '
FINANCIAL_API_KEY = os.environ.get('FINANCIAL_API_KEY', config.FINANCIAL_API_KEY)

def process(input, entities=None):
output = {}
stock=''
try:
url = f'https://eodhistoricaldata.com/api/news?api_token={FINANCIAL_API_KEY}&s={stock}'
news_json = requests.get(url)
data= news_json.json()
template = GenericTemplate()
for i in range(5):
title = data[-i]['title']
output.append(title)
buttons = ButtonTemplate()
buttons.add_web_url('Read more...', url)
buttons.add_web_url('Powered by Financial News API', 'https://eodhistoricaldata.com/')
template.add_element(title=title, buttons=buttons.get_buttons())
print(cl('{}. '.format(i+1), attrs = ['bold']), '{}'.format(title))
output['input'] = input
output['output'] = template.get_message()
output['success'] = True
except:
error_message = 'There was some error while retrieving data from Financial News API.'
output['error_msg'] = TextTemplate(error_message).get_message()
output['success'] = False
return output

8 changes: 8 additions & 0 deletions modules/tests/test_financial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import modules


def test_news():
assert ('financial' == modules.process_query('financial')[0])
assert ('financial' == modules.process_query('financial news')[0])
assert ('financial' == modules.process_query('economic news')[0])
assert ('financial' != modules.process_query('something random')[0])