All functions fixed for markdown bug

This commit is contained in:
Florian Kellermann 2022-05-10 21:51:27 +02:00
parent c6352c5f75
commit ed26c6969d
3 changed files with 11 additions and 11 deletions

View File

@ -226,7 +226,6 @@ def update_for_user(message):
share_symbols = [] share_symbols = []
share_amounts = [] share_amounts = []
share_courses = []
my_portfolio = p_my_handler.get_user_portfolio(p_user_id) my_portfolio = p_my_handler.get_user_portfolio(p_user_id)
@ -235,15 +234,15 @@ def update_for_user(message):
print(element["count"], element["isin"]) print(element["count"], element["isin"])
share_symbols.append(element["isin"]) share_symbols.append(element["isin"])
share_amounts.append(element["count"]) share_amounts.append(element["count"])
share_courses.append(element["current_price"])
my_user = p_my_handler.get_user(p_user_id) my_user = p_my_handler.get_user(p_user_id)
send_to_user("Hello %s this is your share update:"%str(my_user["username"]), pUser_id=p_user_id) send_to_user("Hello %s this is your share update:"%str(my_user["username"]), pUser_id=p_user_id)
if len(share_symbols) != 0: if len(share_symbols) != 0:
for i in range(len(share_symbols)): for i in range(len(share_symbols)):
my_update_message = f'Symbol: {share_symbols[i]}\nCurrent Price per Share: {share_courses[i]}\nAmount owned: {share_amounts[i]}\nTotal Investment: {float(share_courses[i]) * float(share_amounts[i])}' my_price = share_fetcher.get_share_price_no_currency(share_symbols[i])
send_to_user(my_update_message, pUser_id=p_user_id) my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {share_amounts[i]}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR'
bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2")
else: else:
send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id) send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id)
@ -281,8 +280,8 @@ def send_share_update(message):
bot.register_next_step_handler(message, send_share_price) bot.register_next_step_handler(message, send_share_price)
def send_share_price(message): def send_share_price(message):
str_share_price = share_fetcher.get_share_information_simple(str(message.text)) str_share_price = share_fetcher.get_share_information_markdown(str(message.text))
bot.reply_to(message, str_share_price) bot.reply_to(message, str_share_price, parse_mode="MARKDOWNV2")
@bot.message_handler(commands=['allnews', 'Allnews']) # /allnews -> get all news @bot.message_handler(commands=['allnews', 'Allnews']) # /allnews -> get all news
@ -607,7 +606,7 @@ def send_shares(message):
bot.send_message(chat_id=user_id, text='You do not have any shares. Add shares on https://gruppe1.testsites.info') bot.send_message(chat_id=user_id, text='You do not have any shares. Add shares on https://gruppe1.testsites.info')
else: else:
for element in shares: for element in shares:
bot.send_message(chat_id=user_id, text=share_fetcher.get_share_information_simple(element)) bot.send_message(chat_id=user_id, text=share_fetcher.get_share_information_markdown(element), parse_mode="MARKDOWNV2")

View File

@ -148,8 +148,8 @@ def update_for_user(p_user_id, p_my_handler):
if len(share_symbols) != 0: if len(share_symbols) != 0:
for i in range(len(share_symbols)): for i in range(len(share_symbols)):
my_price = share_fetcher.get_share_price_no_currency(share_symbols[i]) my_price = share_fetcher.get_share_price_no_currency(share_symbols[i])
my_update_message = f'{share_fetcher.get_share_information_simple(share_symbols[i])}\nAmount owned: {share_amounts[i]}\nTotal Investment: {round(float(my_price) * float(share_amounts[i]), 2)} EUR' my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {share_amounts[i]}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR'
send_to_user(my_update_message, pUser_id=p_user_id) bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2")
else: else:
send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id) send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id)
@ -157,7 +157,7 @@ def update_for_user(p_user_id, p_my_handler):
if len(shares)!=0: # Send updates on watchlist shares if existing if len(shares)!=0: # Send updates on watchlist shares if existing
send_to_user("Your watchlist shares:", pUser_id=p_user_id) send_to_user("Your watchlist shares:", pUser_id=p_user_id)
for element in shares: for element in shares:
send_to_user(share_fetcher.get_share_information_simple(element), pUser_id=p_user_id) send_to_user(share_fetcher.get_share_information_markdown(element), pUser_id=p_user_id, md_mode=True)
keywords = p_my_handler.get_user_keywords(p_user_id) # get keywords as array keywords = p_my_handler.get_user_keywords(p_user_id) # get keywords as array

View File

@ -9,6 +9,7 @@ __license__ = "None"
import investpy import investpy
import pandas import pandas
from currency_converter import CurrencyConverter from currency_converter import CurrencyConverter
import helper_functions as hf
def get_share_price(str_search_for): def get_share_price(str_search_for):
"""get stock price per share for company name or isin or symbol """get stock price per share for company name or isin or symbol
@ -106,7 +107,7 @@ def get_share_information_markdown(str_search_for):
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
countries=['germany'], n_results=1) countries=['germany'], n_results=1)
str_return = f'*{search_result.name}*\n_{search_result.symbol}_\nworth: {get_share_price(str_search_for)}' str_return = f'*{hf.make_markdown_proof(search_result.name)}*\n_{hf.make_markdown_proof(search_result.symbol)}_\nworth: {hf.make_markdown_proof(get_share_price(str_search_for))}'
return str_return return str_return
def get_share_information_simple(str_search_for): def get_share_information_simple(str_search_for):