From b63744d08a971c91ae9c5b06b94606ccacf0cb97 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 10 May 2022 09:49:31 +0200 Subject: [PATCH] implemented /transactions and added /shares --- telegram_bot/bot.py | 50 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index b3158c7..866e3a5 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -83,7 +83,7 @@ def send_help(message): :rtype: none """ - bot.reply_to(message, "/id or /auth get your user id\n/update get updates on your shares.\n/setAdmin set admin rights of user (ADMIN)\n/users see all users. (ADMIN)\n/me get my user info\n/news get top article for each keyword.\n/allnews get all news (last 7 days)\n/keywords get all your keywords\n/addkeyword add a keyword\n/removekeyword remove a keyword\n/share get price of specific share\n/portfolio see own portfolio\n/newtransaction add new transaction\n/interval get update interval\n/setinterval set update interval\n_For further details see https://gruppe1.testsites.info _", parse_mode='MARKDOWN') + bot.reply_to(message, "/id or /auth get your user id\n/update get updates on your shares.\n/shares get update on interesting shares\n/setAdmin set admin rights of user (ADMIN)\n/users see all users. (ADMIN)\n/me get my user info\n/news get top article for each keyword.\n/allnews get all news (last 7 days)\n/keywords get all your keywords\n/addkeyword add a keyword\n/removekeyword remove a keyword\n/transactions get all transactions\n/share get price of specific share\n/portfolio see own portfolio\n/removeshare removes share from portfolio\n/interval get update interval\n/setinterval set update interval\n_For further details see https://gruppe1.testsites.info _", parse_mode='MARKDOWN') @bot.message_handler(commands=['users', 'Users']) # /users -> sending all users @@ -544,7 +544,55 @@ def send_interval(message): return formatted_interval = str(interval).replace(' ', '_') # replace spaces with underscores to add to url of crontab.guru bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})') + + +@bot.message_handler(commands=['transactions', 'Transactions']) +def send_transactions(message): + """ send transactions for user + :type message: message object bot + :param message: message that was reacted to, in this case always '/transactions' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + transactions = api_handler.get_user_transactions(user_id) # get transactions of user + + if transactions == None: # true if user does not exist + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') + return + + if not transactions: # true if user has no transactions + bot.send_message(chat_id=user_id, text='You do not have any transactions.') + return + else: + for transaction in transactions: + bot.send_message(chat_id=user_id, text=f'_{transaction["comment"]}_\n{transaction["isin"]}\namount: {transaction["count"]}\nprice: {transaction["price"]}\ntime: {transaction["time"]}', parse_mode="MARKDOWN") + + +@bot.message_handler(commands=['shares', 'Shares']) +def send_shares(message): + """ send shares for user + :type message: message object bot + :param message: message that was reacted to, in this case always '/shares' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + shares = api_handler.get_user_shares(user_id) # get shares of user + + if shares == None: # true if user does not exist + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') + + if not shares: # true if user has no shares + bot.send_message(chat_id=user_id, text='You do not have any shares. Add shares on https://gruppe1.testsites.info') + + # tbd (flo) + @bot.message_handler(commands=['setinterval', 'Setinterval']) def set_new_interval(message):