1
0
mirror of https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git synced 2025-08-02 19:41:26 +00:00

replaced formatting with f strings

This commit is contained in:
2019-02-22 11:57:21 -07:00
parent b6eb8b55f0
commit e210b9ad0e
2 changed files with 16 additions and 41 deletions

View File

@@ -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(
@@ -113,9 +99,10 @@ def stockInfo(bot, update):
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)
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
tickerData = tickerInfo.tickerQuote(tickers)
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
for ticker in tickers:
ticker = ticker.upper()
# Makes sure ticker exists
@@ -123,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
)
@@ -151,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)