Fixing stock as yahoo deprecated their endpoints, fixes #37
This commit is contained in:
parent
e9ad31fcc8
commit
72a0330c39
@ -7,4 +7,3 @@ pyowm
|
||||
requests
|
||||
wikipedia
|
||||
wolframalpha
|
||||
yahoo-finance
|
||||
|
21
app/stock.py
21
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user