Update message working, regularity still needs implementation
This commit is contained in:
parent
44c57aa881
commit
6db3a7ce32
@ -7,6 +7,7 @@ __version__ = "0.0.1"
|
|||||||
__license__ = "None"
|
__license__ = "None"
|
||||||
|
|
||||||
from calendar import month
|
from calendar import month
|
||||||
|
from symtable import Symbol
|
||||||
from shares.share_fetcher import get_share_price
|
from shares.share_fetcher import get_share_price
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
@ -42,17 +43,9 @@ def main_loop():
|
|||||||
current_time_datetime = datetime.datetime.now()
|
current_time_datetime = datetime.datetime.now()
|
||||||
my_handler = API_Handler("https://gruppe1.testsites.info/api", "bot@example.com", "bot")
|
my_handler = API_Handler("https://gruppe1.testsites.info/api", "bot@example.com", "bot")
|
||||||
|
|
||||||
print(time.ctime()) # Debug
|
|
||||||
|
|
||||||
"""p1 = Process(target= update_crontab, args=(current_time_datetime, my_handler ))
|
# update_for_user(5270256395, my_handler) # Debug (running test update for kevins shares)
|
||||||
p1.start()
|
|
||||||
time.sleep(5)
|
|
||||||
p3 = Process(target= update_based_on_crontab, args=() )
|
|
||||||
p3.daemon = True
|
|
||||||
p3.start()
|
|
||||||
p1.join()
|
|
||||||
p3.terminate()
|
|
||||||
p1.terminate()"""
|
|
||||||
|
|
||||||
update_crontab(current_time_datetime, my_handler)
|
update_crontab(current_time_datetime, my_handler)
|
||||||
|
|
||||||
@ -122,8 +115,31 @@ def update_based_on_crontab(p_user_ids, p_user_crontab):
|
|||||||
|
|
||||||
my_scheduler.start()
|
my_scheduler.start()
|
||||||
|
|
||||||
def update_for_user(p_user_id):
|
def update_for_user(p_user_id, p_my_handler):
|
||||||
print("updating for {p_user_id}")
|
|
||||||
|
share_symbols = []
|
||||||
|
share_amounts = []
|
||||||
|
share_courses = []
|
||||||
|
|
||||||
|
my_portfolio = p_my_handler.get_user_portfolio(p_user_id)
|
||||||
|
|
||||||
|
for element in my_portfolio:
|
||||||
|
if element["count"] != '' and element["symbol"]!= '':
|
||||||
|
print(element["count"], element["symbol"])
|
||||||
|
share_symbols.append(element["symbol"])
|
||||||
|
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:"%str(my_user["username"]), pUser_id=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])}'
|
||||||
|
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/api to change your settings and add shares.")
|
||||||
|
|
||||||
|
|
||||||
def send_to_user(pText, pUser_id = 1770205310):
|
def send_to_user(pText, pUser_id = 1770205310):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user