mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 23:26:52 +00:00
added error handling for if ticker doesnt exist
This commit is contained in:
parent
a195c87b6e
commit
230f6fdeac
@ -26,6 +26,7 @@ def tickerDataReply(tickers: list):
|
|||||||
IEXURL = (
|
IEXURL = (
|
||||||
f"https://cloud.iexapis.com/stable/stock/{ticker}/quote?token={cred.secret}"
|
f"https://cloud.iexapis.com/stable/stock/{ticker}/quote?token={cred.secret}"
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
with urllib.request.urlopen(IEXURL) as url:
|
with urllib.request.urlopen(IEXURL) as url:
|
||||||
IEXData = json.loads(url.read().decode())
|
IEXData = json.loads(url.read().decode())
|
||||||
|
|
||||||
@ -39,6 +40,8 @@ def tickerDataReply(tickers: list):
|
|||||||
reply += f", the stock is currently **down {change}%**"
|
reply += f", the stock is currently **down {change}%**"
|
||||||
else:
|
else:
|
||||||
reply += ", the stock hasn't shown any movement today."
|
reply += ", the stock hasn't shown any movement today."
|
||||||
|
except:
|
||||||
|
reply = f"The ticker: {ticker} was not found."
|
||||||
|
|
||||||
tickerReplies[ticker] = reply
|
tickerReplies[ticker] = reply
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user