\shares working now and also sensing with daily update. Daily update message prettier
This commit is contained in:
parent
00eeb1c924
commit
7eaddabadc
@ -587,11 +587,12 @@ def send_shares(message):
|
||||
|
||||
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
|
||||
elif 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')
|
||||
else:
|
||||
for element in shares:
|
||||
bot.send_message(chat_id=user_id, text=share_fetcher.get_share_information_simple(element))
|
||||
|
||||
# tbd (flo)
|
||||
|
||||
|
||||
@bot.message_handler(commands=['setinterval', 'Setinterval'])
|
||||
|
@ -14,6 +14,7 @@ from bot import bot
|
||||
import sys
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from api_handling.api_handler import API_Handler
|
||||
import shares.share_fetcher as share_fetcher
|
||||
|
||||
|
||||
'''
|
||||
@ -137,18 +138,27 @@ def update_for_user(p_user_id, p_my_handler):
|
||||
print(element["count"], element["isin"])
|
||||
share_symbols.append(element["isin"])
|
||||
share_amounts.append(element["count"])
|
||||
share_courses.append(element["current_price"])
|
||||
|
||||
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)
|
||||
|
||||
shares = p_my_handler.get_user_shares(p_user_id)
|
||||
|
||||
if len(share_symbols) != 0:
|
||||
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])
|
||||
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'
|
||||
send_to_user(my_update_message, pUser_id=p_user_id)
|
||||
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)
|
||||
|
||||
|
||||
if len(shares)!=0: # Send updates on watchlist shares if existing
|
||||
send_to_user("Your watchlist shares:", pUser_id=p_user_id)
|
||||
for element in shares:
|
||||
send_to_user(share_fetcher.get_share_information_simple(element), pUser_id=p_user_id)
|
||||
|
||||
|
||||
keywords = p_my_handler.get_user_keywords(p_user_id) # get keywords as array
|
||||
|
||||
if(keywords): # if keywords exist and array is not empty
|
||||
|
@ -58,10 +58,8 @@ def get_share_price(str_search_for):
|
||||
|
||||
def get_share_price_no_currency(str_search_for):
|
||||
"""get stock price per share for company name or isin or symbol no currency
|
||||
|
||||
Args:
|
||||
str_search_for (string): search for this string/isin
|
||||
|
||||
Returns: none
|
||||
"""
|
||||
try:
|
||||
@ -96,7 +94,6 @@ def get_share_price_no_currency(str_search_for):
|
||||
|
||||
return str_return
|
||||
|
||||
|
||||
def get_share_information(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
@ -105,8 +102,19 @@ def get_share_information(str_search_for):
|
||||
|
||||
return str_return
|
||||
|
||||
def get_share_information_markdown(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
str_return = f'*{search_result.name}*\n_{search_result.symbol}_\nworth: {get_share_price(str_search_for)}'
|
||||
return str_return
|
||||
|
||||
def get_share_information_simple(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
str_return = search_result.name + "\n" +search_result.symbol + "\nworth: " + get_share_price(str_search_for)
|
||||
return str_return
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_share_price("US2515661054"))
|
||||
print(get_share_price("DE0005557508"))
|
||||
print(get_share_price_no_currency("US2515661054"))
|
||||
print(get_share_price_no_currency("DE0005557508"))
|
||||
print("None")
|
Loading…
Reference in New Issue
Block a user