mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 15:17:28 +00:00
Merge branch 'Features' into 'master'
replaced formatting with f strings and fixed news bug See merge request MisterBiggs/simple-telegram-bot!8
This commit is contained in:
commit
0e14b183fa
@ -65,36 +65,22 @@ def news(bot, update):
|
||||
price = tickerData[ticker + "Price"]
|
||||
change = tickerData[ticker + "Change"]
|
||||
|
||||
message = (
|
||||
"The current stock price of "
|
||||
+ name
|
||||
+ " is $**"
|
||||
+ str(price)
|
||||
+ "**"
|
||||
)
|
||||
message = f"The current stock price of {name} is $**{price}**"
|
||||
if change > 0:
|
||||
message = (
|
||||
message
|
||||
+ ", the stock is currently **up "
|
||||
+ str(change)
|
||||
+ "%**"
|
||||
)
|
||||
message = f"{message}, the stock is currently **up {change}%**"
|
||||
elif change < 0:
|
||||
message = (
|
||||
message
|
||||
+ ", the stock is currently **down "
|
||||
+ str(change)
|
||||
+ "%**"
|
||||
f"{message}, the stock is currently **down {change}%**"
|
||||
)
|
||||
else:
|
||||
message = (
|
||||
message + ", the stock hasn't shown any movement today."
|
||||
f"{message}, the stock hasn't shown any movement today."
|
||||
)
|
||||
|
||||
news = tickerInfo.stockNews(ticker)
|
||||
for i in range(3):
|
||||
message = "{}\n\n[{}]({})".format(
|
||||
message, news["title"][i], news["link"][i]
|
||||
message = (
|
||||
f"{message}\n\n[{news['title'][i]}]({news['link'][i]})"
|
||||
)
|
||||
|
||||
update.message.reply_text(
|
||||
@ -124,22 +110,13 @@ def stockInfo(bot, update):
|
||||
name = tickerData[ticker + "Name"]
|
||||
price = tickerData[ticker + "Price"]
|
||||
change = tickerData[ticker + "Change"]
|
||||
message = (
|
||||
"The current stock price of " + name + " is $**" + str(price) + "**"
|
||||
)
|
||||
message = f"The current stock price of {name} is $**{price}**"
|
||||
if change > 0:
|
||||
message = (
|
||||
message + ", the stock is currently **up " + str(change) + "%**"
|
||||
)
|
||||
message = f"{message}, the stock is currently **up {change}%**"
|
||||
elif change < 0:
|
||||
message = (
|
||||
message
|
||||
+ ", the stock is currently **down "
|
||||
+ str(change)
|
||||
+ "%**"
|
||||
)
|
||||
message = f"{message}, the stock is currently **down {change}%**"
|
||||
else:
|
||||
message = message + ", the stock hasn't shown any movement today."
|
||||
message = f"{message}, the stock hasn't shown any movement today."
|
||||
update.message.reply_text(
|
||||
text=message, parse_mode=telegram.ParseMode.MARKDOWN
|
||||
)
|
||||
@ -152,7 +129,6 @@ def stockInfo(bot, update):
|
||||
def dividend(bot, update):
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
print("div")
|
||||
try:
|
||||
# regex to find tickers in messages, looks for up to 4 word characters following a dollar sign and captures the 4 word characters
|
||||
tickers = re.findall("[$](\w{1,4})", message)
|
||||
|
@ -38,7 +38,7 @@ def stockNews(ticker):
|
||||
"""Makes a bunch of strings that are links to news websites for an input ticker"""
|
||||
print("Gather News on " + ticker)
|
||||
|
||||
newsLink = "https://api.iextrading.com/1.0/stock/{}/news/last/5".format(ticker)
|
||||
newsLink = f"https://api.iextrading.com/1.0/stock/{ticker}/news/last/5"
|
||||
|
||||
with urllib.request.urlopen(newsLink) as url:
|
||||
data = json.loads(url.read().decode())
|
||||
@ -52,12 +52,12 @@ def stockNews(ticker):
|
||||
|
||||
def stockLogo(ticker):
|
||||
"""returns a png of an input ticker"""
|
||||
logoURL = "https://g.foolcdn.com/art/companylogos/mark/" + ticker + ".png"
|
||||
logoURL = f"https://g.foolcdn.com/art/companylogos/mark/{ticker}.png"
|
||||
return logoURL
|
||||
|
||||
|
||||
def stockInfo(ticker):
|
||||
infoURL = "https://api.iextrading.com/1.0/stock/{}/stats".format(ticker)
|
||||
infoURL = f"https://api.iextrading.com/1.0/stock/{ticker}/stats"
|
||||
|
||||
with urllib.request.urlopen(infoURL) as url:
|
||||
data = json.loads(url.read().decode())
|
||||
@ -99,9 +99,7 @@ def stockDividend(ticker):
|
||||
h, m = divmod(h, 3600)
|
||||
m, s = divmod(m, 60)
|
||||
|
||||
countdownMessage = "\n\nThe dividend is in: {:.0f} Days {:.0f} Hours {:.0f} Minutes {:.0f} Seconds.".format(
|
||||
d, h, m, s
|
||||
)
|
||||
countdownMessage = f"\n\nThe dividend is in: {d:.0f} Days {h:.0f} Hours {m:.0f} Minutes {s:.0f} Seconds."
|
||||
|
||||
message = line1 + countdownMessage
|
||||
return message
|
||||
|
Loading…
x
Reference in New Issue
Block a user