1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-06-16 15:17:28 +00:00

added comments for new features

This commit is contained in:
Anson 2019-02-04 14:42:06 -07:00
parent 7ad7d17e70
commit aa31b0cfa7
2 changed files with 9 additions and 1 deletions

View File

@ -43,14 +43,16 @@ def news(bot, update):
tickers = re.findall("[$](\w{1,4})", message) tickers = re.findall("[$](\w{1,4})", message)
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING) bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
## Checks if a ticker was passed in
if tickers == []: if tickers == []:
update.message.reply_text( update.message.reply_text(
"Please type a ticker after your command: /news $tsla" "Please type a ticker after your command with a dollar sign: /news $tsla"
) )
else: else:
tickerData = tickerInfo.tickerQuote(tickers) tickerData = tickerInfo.tickerQuote(tickers)
for ticker in tickers: for ticker in tickers:
ticker = ticker.upper() ticker = ticker.upper()
#Makes sure ticker exists
if tickerData[ticker] == 1: if tickerData[ticker] == 1:
name = tickerData[ticker + "Name"] name = tickerData[ticker + "Name"]
price = tickerData[ticker + "Price"] price = tickerData[ticker + "Price"]
@ -107,6 +109,7 @@ def stockInfo(bot, update):
tickerData = tickerInfo.tickerQuote(tickers) tickerData = tickerInfo.tickerQuote(tickers)
for ticker in tickers: for ticker in tickers:
ticker = ticker.upper() ticker = ticker.upper()
#Makes sure ticker exists
if tickerData[ticker] == 1: if tickerData[ticker] == 1:
name = tickerData[ticker + "Name"] name = tickerData[ticker + "Name"]
price = tickerData[ticker + "Price"] price = tickerData[ticker + "Price"]

View File

@ -3,6 +3,7 @@ import json
def tickerQuote(tickers): def tickerQuote(tickers):
"""Gathers information from IEX api on stock"""
stockData = {} stockData = {}
IEXURL = ( IEXURL = (
"https://api.iextrading.com/1.0/stock/market/batch?symbols=" "https://api.iextrading.com/1.0/stock/market/batch?symbols="
@ -15,6 +16,8 @@ def tickerQuote(tickers):
for ticker in tickers: for ticker in tickers:
ticker = ticker.upper() ticker = ticker.upper()
# Makes sure ticker exists before populating a dictionary
if ticker in IEXData: if ticker in IEXData:
stockData[ticker] = 1 stockData[ticker] = 1
stockData[ticker + "Name"] = IEXData[ticker]["quote"]["companyName"] stockData[ticker + "Name"] = IEXData[ticker]["quote"]["companyName"]
@ -31,6 +34,7 @@ def tickerQuote(tickers):
def stockNewsList(ticker): def stockNewsList(ticker):
"""Makes a bunch of strings that are links to news websites for an input ticker"""
print("Gather News on " + ticker) print("Gather News on " + ticker)
news = { news = {
"Bravos": "https://bravos.co/" + ticker, "Bravos": "https://bravos.co/" + ticker,
@ -46,5 +50,6 @@ def stockNewsList(ticker):
def stockLogo(ticker): def stockLogo(ticker):
"""returns a png of an input ticker"""
logoURL = "https://g.foolcdn.com/art/companylogos/mark/" + ticker + ".png" logoURL = "https://g.foolcdn.com/art/companylogos/mark/" + ticker + ".png"
return logoURL return logoURL