diff --git a/app/requirements.txt b/app/requirements.txt index 573ca728..5648ee1b 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -7,4 +7,3 @@ pyowm requests wikipedia wolframalpha -yahoo-finance diff --git a/app/stock.py b/app/stock.py index fa2da4d7..65da25ae 100644 --- a/app/stock.py +++ b/app/stock.py @@ -1,21 +1,24 @@ -import yahoo_finance +import requests def parse_share(msg): if len(msg.split()) > 1: - print(msg.split()[1:]) try: res = '' for s in msg.split()[1:]: res = '{}\n\n{}'.format(res, get_stock(s)) - except yahoo_finance.YQLResponseMalformedError: + except: res = '```Please input valid shares: !stock [share_name]```' return res return '```Please input at least one valid share: !stock [share_name]```' def get_stock(share_name): - share = yahoo_finance.Share(share_name) - open_price = share.get_open() - curr_price = share.get_price() - change = float(curr_price) - float(open_price) - return '```Stock: {}\n\nOpen: ${}\nCurrently: ${}\nChange: ${}```'.format( - share_name.upper(), open_price, curr_price, change) + + url = "https://api.iextrading.com/1.0/stock/{}/quote".format(share_name) + request = requests.get(url).json() + + open_price = request['open'] + curr_price = request['latestPrice'] + change = request['change'] + changePercent = request['changePercent'] + return '```Company Name: {}\nSymbol: {}\nSector: {}\n\nOpen: ${}\nCurrently: ${}\nChange: ${}\nChange percent {}%```'.format( + request['companyName'], request['symbol'], request['sector'], open_price, curr_price, change, changePercent)