|
|
|
@@ -63,8 +63,13 @@ def update_crontab(p_my_handler):
|
|
|
|
|
|
|
|
|
|
global user_crontab
|
|
|
|
|
global user_ids
|
|
|
|
|
|
|
|
|
|
all_users = p_my_handler.get_all_users() # get all users so crontabs can update for everybody
|
|
|
|
|
|
|
|
|
|
all_users = p_my_handler.get_all_users() # get all users so crontabs can update for everybody
|
|
|
|
|
|
|
|
|
|
if all_users == None:
|
|
|
|
|
print("No users found, trying again.")
|
|
|
|
|
update_crontab(p_my_handler)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
user_ids = []
|
|
|
|
|
user_crontab = []
|
|
|
|
@@ -75,10 +80,9 @@ def update_crontab(p_my_handler):
|
|
|
|
|
user_ids.append(int(element["telegram_user_id"]))
|
|
|
|
|
try:
|
|
|
|
|
user_crontab.append(str(element["cron"]))
|
|
|
|
|
except:
|
|
|
|
|
user_ids.pop() # if something goes wrong with cron I have to delete matching user id
|
|
|
|
|
except:
|
|
|
|
|
continue
|
|
|
|
|
except:
|
|
|
|
|
user_ids.pop() # if something goes wrong with cron I have to delete matching user id
|
|
|
|
|
except: continue
|
|
|
|
|
|
|
|
|
|
print(user_ids)
|
|
|
|
|
|
|
|
|
@@ -130,27 +134,30 @@ def update_for_user(p_user_id, p_my_handler):
|
|
|
|
|
"""
|
|
|
|
|
share_symbols = []
|
|
|
|
|
share_amounts = []
|
|
|
|
|
|
|
|
|
|
my_portfolio = p_my_handler.get_user_portfolio(p_user_id) # get all existing shares for user
|
|
|
|
|
|
|
|
|
|
my_portfolio = p_my_handler.get_user_portfolio(p_user_id) # get all existing shares for user
|
|
|
|
|
|
|
|
|
|
for element in my_portfolio:
|
|
|
|
|
if element["count"] != '' and element["isin"] != '':
|
|
|
|
|
print(element["count"], element["isin"])
|
|
|
|
|
share_symbols.append(element["isin"])
|
|
|
|
|
share_amounts.append(element["count"])
|
|
|
|
|
if my_portfolio!=None:
|
|
|
|
|
for element in my_portfolio:
|
|
|
|
|
if element["count"] != '' and element["isin"] != '':
|
|
|
|
|
print(element["count"], element["isin"])
|
|
|
|
|
share_symbols.append(element["isin"])
|
|
|
|
|
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 for today:" % str(my_user["username"]), pUser_id=p_user_id)
|
|
|
|
|
send_to_user("Hello %s this is your update for today:"%str(my_user["username"]), pUser_id=p_user_id)
|
|
|
|
|
|
|
|
|
|
shares = p_my_handler.get_user_shares(p_user_id) # all interest shares
|
|
|
|
|
|
|
|
|
|
shares = p_my_handler.get_user_shares(p_user_id) # all interest shares
|
|
|
|
|
if shares!=None
|
|
|
|
|
if len(share_symbols) != 0: # iterate through all shares
|
|
|
|
|
|
|
|
|
|
if len(share_symbols) != 0: # iterate through all shares
|
|
|
|
|
for i in range(len(share_symbols)):
|
|
|
|
|
my_price = share_fetcher.get_share_price_no_currency(share_symbols[i])
|
|
|
|
|
my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {hf.make_markdown_proof(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:
|
|
|
|
|
send_to_user("No shares found for your account. Check " + os.getenv("WEBSITE_URL") + " to change your settings and add shares.", pUser_id=p_user_id)
|
|
|
|
|
for i in range(len(share_symbols)):
|
|
|
|
|
my_price = share_fetcher.get_share_price_no_currency(share_symbols[i])
|
|
|
|
|
my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {hf.make_markdown_proof(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:
|
|
|
|
|
send_to_user("No shares found for your account. Check " + os.getenv("WEBSITE_URL") + " to change your settings and add shares.", pUser_id=p_user_id)
|
|
|
|
|
|
|
|
|
|
if len(shares) != 0: # Send updates on watchlist shares if existing
|
|
|
|
|
send_to_user("Your watchlist shares:", pUser_id=p_user_id)
|
|
|
|
|