Delete portfolio function, all markdown fixed, new version and /help changed
This commit is contained in:
parent
f81d99e1a9
commit
12f234c0a5
@ -29,7 +29,7 @@ from api_handling.api_handler import API_Handler
|
|||||||
|
|
||||||
load_dotenv(dotenv_path='.env') # load environment variables
|
load_dotenv(dotenv_path='.env') # load environment variables
|
||||||
|
|
||||||
bot_version = "2.0.1" # version of bot
|
bot_version = "3.0.1" # version of bot
|
||||||
|
|
||||||
# create api handler
|
# create api handler
|
||||||
api_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) # get creds from env vars.
|
api_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) # get creds from env vars.
|
||||||
@ -78,7 +78,7 @@ def send_help(message):
|
|||||||
:rtype: none
|
:rtype: none
|
||||||
"""
|
"""
|
||||||
bot.reply_to(message,
|
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/newtransaction create new transaction\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")
|
"/id or /auth get your user id\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/newtransaction create new transaction\n/share get price of specific share\n/portfolio see own stock 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")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['users', 'Users']) # /users -> sending all users
|
@bot.message_handler(commands=['users', 'Users']) # /users -> sending all users
|
||||||
@ -208,7 +208,7 @@ def send_status(message):
|
|||||||
bot.reply_to(message, "bot is running")
|
bot.reply_to(message, "bot is running")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['update', 'Update']) # /update -> update shares
|
@bot.message_handler(commands=['portfolio', 'Portfolio']) # /update -> update shares
|
||||||
def update_for_user(message):
|
def update_for_user(message):
|
||||||
p_user_id = int(message.from_user.id)
|
p_user_id = int(message.from_user.id)
|
||||||
p_my_handler = api_handler
|
p_my_handler = api_handler
|
||||||
@ -218,14 +218,20 @@ def update_for_user(message):
|
|||||||
|
|
||||||
my_portfolio = p_my_handler.get_user_portfolio(p_user_id)
|
my_portfolio = p_my_handler.get_user_portfolio(p_user_id)
|
||||||
|
|
||||||
|
if my_portfolio == None: # true if user is not registered
|
||||||
|
bot.send_message(chat_id=p_user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info')
|
||||||
|
return
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
for element in my_portfolio:
|
for element in my_portfolio:
|
||||||
if element["count"] != '' and element["isin"] != '':
|
if element["count"] != '' and element["isin"] != '':
|
||||||
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"])
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if len(share_symbols) != 0:
|
if len(share_symbols) != 0:
|
||||||
for i in range(len(share_symbols)):
|
for i in range(len(share_symbols)):
|
||||||
@ -426,33 +432,6 @@ def send_keywords(message):
|
|||||||
bot.send_message(chat_id=user_id, text=text, parse_mode="MARKDOWNV2")
|
bot.send_message(chat_id=user_id, text=text, parse_mode="MARKDOWNV2")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['portfolio', 'Portfolio'])
|
|
||||||
def send_portfolio(message):
|
|
||||||
""" Send portfolio of user
|
|
||||||
:type message: message object bot
|
|
||||||
:param message: message that was reacted to, in this case always '/portfolio'
|
|
||||||
|
|
||||||
:raises: none
|
|
||||||
|
|
||||||
:rtype: none
|
|
||||||
"""
|
|
||||||
user_id = int(message.from_user.id)
|
|
||||||
portfolio = api_handler.get_user_portfolio(user_id) # get portfolio of user as json
|
|
||||||
if portfolio == None: # true if user is not registered
|
|
||||||
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 portfolio: # true if user is registered but does not have any stocks in portfolio
|
|
||||||
bot.send_message(chat_id=user_id, text='You do not have any stocks in your portfolio.')
|
|
||||||
return
|
|
||||||
else: # send portfolio
|
|
||||||
for stock in portfolio:
|
|
||||||
comment = hf.make_markdown_proof(str(stock["comment"])) # comment may be written name of stock, comment is made by user when adding an stock to portfolio
|
|
||||||
count = hf.make_markdown_proof("{:.2f}".format(float(stock["count"]))) # round count to 2 decimal places
|
|
||||||
isin = hf.make_markdown_proof(str(stock["isin"]))
|
|
||||||
worth = hf.make_markdown_proof("{:.2f}".format(float(stock["current_price"]) * float(stock["count"]))) # round current_price to 2 decimal places
|
|
||||||
bot.send_message(chat_id=user_id, text=f'*{comment}*\n_{isin}_\namount: {count}\nworth: ${worth}', parse_mode="MARKDOWNV2") # formatted message in markdown
|
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['removeshare', 'Removeshare'])
|
@bot.message_handler(commands=['removeshare', 'Removeshare'])
|
||||||
def remove_share(message):
|
def remove_share(message):
|
||||||
""" Remove share from portfolio
|
""" Remove share from portfolio
|
||||||
|
Loading…
Reference in New Issue
Block a user