1
0
mirror of https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git synced 2025-07-28 00:51:22 +00:00

ported news and info commands from telegram bot

This commit is contained in:
2019-06-11 05:37:10 -07:00
parent d0b04a253b
commit cf6b03e31a
2 changed files with 61 additions and 0 deletions

View File

@@ -78,3 +78,46 @@ def tickerDividend(tickers: list):
messages[ticker] = f"{ticker} either doesn't exist or pays no dividend."
return messages
def tickerNews(tickers: list):
messages = {}
for ticker in tickers:
IEXurl = f"https://cloud.iexapis.com/stable/stock/{ticker}/news/last/3?token={IEX_TOKEN}"
with urllib.request.urlopen(IEXurl) as url:
data = json.loads(url.read().decode())
if data:
messages[ticker] = f"News for **{ticker.upper()}**:\n"
for news in data:
message = f"\t[{news['headline']}]({news['url']})\n\n"
messages[ticker] = messages[ticker] + message
else:
messages[
ticker
] = f"No news found for: {ticker}\nEither today is boring or the ticker does not exist."
return messages
def tickerInfo(tickers: list):
messages = {}
for ticker in tickers:
IEXurl = (
f"https://cloud.iexapis.com/stable/stock/{ticker}/company?token={IEX_TOKEN}"
)
with urllib.request.urlopen(IEXurl) as url:
data = json.loads(url.read().decode())
if data:
messages[
ticker
] = f"Company Name: [{data['companyName']}]({data['website']})\nIndustry: {data['industry']}\nSector: {data['sector']}\nCEO: {data['CEO']}\nDescription: {data['description']}\n"
else:
messages[
ticker
] = f"No information found for: {ticker}\nEither today is boring or the ticker does not exist."
return messages