fixing and debugging

This commit is contained in:
Linus E 2022-04-17 13:07:57 +02:00
parent caa90a577f
commit 26b41f2c94

View File

@ -115,7 +115,7 @@ def send_welcome(message):
:rtype: none :rtype: none
""" """
bot.reply_to(message, "/id or /auth get your user id\n/update get updates on your shares.\n/users see all users.\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/users see all users.\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.message_handler(commands=['users']) @bot.message_handler(commands=['users'])
@ -140,7 +140,26 @@ def send_all_users(message):
answer = str(known_user.user_id) + ' : ' + known_user.user_name answer = str(known_user.user_id) + ' : ' + known_user.user_name
bot.send_message(chat_id=user_id, text=answer) bot.send_message(chat_id=user_id, text=answer)
@bot.message_handler(commands=['me'])
def send_user(message):
""" Send user data
:type message: message object bot
:param message: message that was reacted to, in this case always containing '/me'
:raises: none
:rtype: none
"""
user_id = int(message.from_user.id)
user_data = api_handler.get_user(user_id) # tbd: formatting
if not user_data or user_data == None:
bot.reply_to(message, "This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info")
return
bot.reply_to(message, 'Your user data:\n' + str(user_data))
@bot.message_handler(commands=['id', 'auth']) # /auth or /id -> Authentication with user_id over web tool @bot.message_handler(commands=['id', 'auth']) # /auth or /id -> Authentication with user_id over web tool
def send_id(message): def send_id(message):
@ -248,7 +267,7 @@ def send_all_news(message):
keywords = api_handler.get_user_keywords(user_id) keywords = api_handler.get_user_keywords(user_id)
if keywords == None: if keywords == None:
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info') 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 return
if not keywords: if not keywords:
@ -286,7 +305,7 @@ def send_news(message):
keywords = api_handler.get_user_keywords(user_id) keywords = api_handler.get_user_keywords(user_id)
if keywords == None: if keywords == None:
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info') 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 return
if not keywords: if not keywords:
@ -369,7 +388,7 @@ def send_keywords(message):
user_id = int(message.from_user.id) user_id = int(message.from_user.id)
keywords = api_handler.get_user_keywords(user_id) keywords = api_handler.get_user_keywords(user_id)
if keywords == None: if keywords == None:
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info') 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 return
if not keywords: if not keywords:
bot.send_message(chat_id=user_id, text='No keywords set for this account. Add keywords by using /addkeyword') bot.send_message(chat_id=user_id, text='No keywords set for this account. Add keywords by using /addkeyword')
@ -392,17 +411,18 @@ def send_portfolio(message):
user_id = int(message.from_user.id) user_id = int(message.from_user.id)
portfolio = api_handler.get_user_portfolio(user_id) portfolio = api_handler.get_user_portfolio(user_id)
if portfolio == None: if portfolio == None:
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info') 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 return
if not portfolio: if not portfolio:
bot.send_message(chat_id=user_id, text='You do not have any stocks in your portfolio.') bot.send_message(chat_id=user_id, text='You do not have any stocks in your portfolio.')
return return
else: else:
portfolio_str = ', '.join(portfolio) # tbd: format portfolio # tbd: format portfolio
bot.send_message(chat_id=user_id, text=f'Your portfolio is: _{portfolio_str}_', parse_mode="MARKDOWN")
bot.send_message(chat_id=user_id, text=f'Your portfolio is: _{str(portfolio)}_', parse_mode="MARKDOWN")
@bot.message_handler(commands=['newtransaction']) #tbd @bot.message_handler(commands=['newtransaction']) #tbd not working rn
def set_new_transaction(message): def set_new_transaction(message):
""" Set new transaction for user """ Set new transaction for user
:type message: message object bot :type message: message object bot
@ -413,14 +433,14 @@ def set_new_transaction(message):
:rtype: none :rtype: none
""" """
user_id = int(message.from_user.id) user_id = int(message.from_user.id)
bot.send_message(chat_id=user_id, text='Type "<symbol>,<amount>,<price_per_stock>" (time of transaction will be set to now):') bot.send_message(chat_id=user_id, text='Type "<symbol>,<amount>,<price_per_stock_usd>" (time of transaction will be set to now):')
bot.register_next_step_handler(message, set_new_transaction_step) bot.register_next_step_handler(message, set_new_transaction_step)
def set_new_transaction_step(message): def set_new_transaction_step(message):
user_id = int(message.from_user.id) user_id = int(message.from_user.id)
if not re.match(r"[A-Za-z0-9]+,[0-9]+[.[0-9]+]?,[0-9]+[.[0-9]+]?", message.text): if not re.match(r"[A-Za-z0-9]+,[0-9]+(.[0-9]+)?,[0-9]+(.[0-9]+)?", message.text):
bot.send_message(chat_id=user_id, text='Invalid format. Try again with /newtransaction.') bot.send_message(chat_id=user_id, text='Invalid format \n(e.g. AAPL,53.2,120.4).\n Try again with /newtransaction.')
return return
transaction_data = str(message.text).split(',') transaction_data = str(message.text).split(',')
@ -428,7 +448,8 @@ def set_new_transaction_step(message):
amount = float(transaction_data[1]) amount = float(transaction_data[1])
price = float(transaction_data[2]) price = float(transaction_data[2])
time = dt.datetime.now() time = dt.datetime.now()
#print("\n\n\n\n\n")
#print(f"{symbol},{amount},{price},{time}")
status = api_handler.set_transaction(user_id, amount, price, symbol, time) status = api_handler.set_transaction(user_id, amount, price, symbol, time)
if status == 200: if status == 200:
@ -448,14 +469,17 @@ def send_interval(message):
:rtype: none :rtype: none
""" """
user_id = int(message.from_user.id) user_id = int(message.from_user.id)
interval = api_handler.get_user(user_id) user_data = api_handler.get_user(user_id)
if interval == None: if user_data == None:
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info and set an interval with /setinterval') 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 and set an interval with /setinterval')
return return
else: else:
interval = str(interval['cron']) interval = str(user_data['cron'])
if interval == 'None':
bot.send_message(chat_id=user_id, text='You do not have an interval set. Set one with /setinterval')
return
formatted_interval = str(interval).replace(' ', '_') formatted_interval = str(interval).replace(' ', '_')
bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})', parse_mode="MARKDOWN") bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})')
@bot.message_handler(commands=['setinterval']) @bot.message_handler(commands=['setinterval'])
@ -483,7 +507,7 @@ def set_new_interval_step(message):
return return
if status == -1: # only -1 when interval is invalid if status == -1: # only -1 when interval is invalid
bot.send_message(chat_id=user_id, text='Invalid interval. Try again with /setinterval.') bot.send_message(chat_id=user_id, text='Invalid interval format. Try again with\n /setinterval.')
return return
else: else:
bot.send_message(chat_id=user_id, text=f'Failed setting interval. (statuscode {status})') bot.send_message(chat_id=user_id, text=f'Failed setting interval. (statuscode {status})')