\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
|
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')
|
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')
|
||||||
|
elif not shares: # true if user has no shares
|
||||||
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')
|
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'])
|
@bot.message_handler(commands=['setinterval', 'Setinterval'])
|
||||||
|
@ -14,6 +14,7 @@ from bot import bot
|
|||||||
import sys
|
import sys
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from api_handling.api_handler import API_Handler
|
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"])
|
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"])
|
||||||
share_courses.append(element["current_price"])
|
|
||||||
|
|
||||||
my_user = p_my_handler.get_user(p_user_id)
|
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 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:
|
if len(share_symbols) != 0:
|
||||||
for i in range(len(share_symbols)):
|
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)
|
send_to_user(my_update_message, pUser_id=p_user_id)
|
||||||
else:
|
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)
|
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
|
keywords = p_my_handler.get_user_keywords(p_user_id) # get keywords as array
|
||||||
|
|
||||||
if(keywords): # if keywords exist and array is not empty
|
if(keywords): # if keywords exist and array is not empty
|
||||||
|
@ -55,13 +55,11 @@ def get_share_price(str_search_for):
|
|||||||
|
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
return "None"
|
return "None"
|
||||||
|
|
||||||
def get_share_price_no_currency(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
|
"""get stock price per share for company name or isin or symbol no currency
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
str_search_for (string): search for this string/isin
|
str_search_for (string): search for this string/isin
|
||||||
|
|
||||||
Returns: none
|
Returns: none
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
@ -96,7 +94,6 @@ def get_share_price_no_currency(str_search_for):
|
|||||||
|
|
||||||
return str_return
|
return str_return
|
||||||
|
|
||||||
|
|
||||||
def get_share_information(str_search_for):
|
def get_share_information(str_search_for):
|
||||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||||
countries=['germany'], n_results=1)
|
countries=['germany'], n_results=1)
|
||||||
@ -105,8 +102,19 @@ def get_share_information(str_search_for):
|
|||||||
|
|
||||||
return str_return
|
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__":
|
if __name__ == "__main__":
|
||||||
print(get_share_price("US2515661054"))
|
print("None")
|
||||||
print(get_share_price("DE0005557508"))
|
|
||||||
print(get_share_price_no_currency("US2515661054"))
|
|
||||||
print(get_share_price_no_currency("DE0005557508"))
|
|
Loading…
Reference in New Issue
Block a user