From 7b99be963311696451a954938062a40ded09ebea Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 15:07:06 +0200 Subject: [PATCH] Updating contrab based on time is working, need api calls --- telegram_bot/bot_updates.py | 51 +++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index d5f351b..e1fe445 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -8,8 +8,10 @@ __license__ = "None" from shares.share_fetcher import get_share_price import time +import datetime from bot import bot import sys +from multiprocessing import Process ''' * * * * * code @@ -34,8 +36,53 @@ def main_loop(): :rtype: none """ - current_time = time.ctime() - send_to_user(current_time) + current_time_datetime = datetime.datetime.now() + + print(time.ctime()) # Debug + + p1 = Process(target= update_crontab, args=(current_time_datetime, )) #Test threading instead of multiprocessing + p1.start() + p3 = Process(target= update_based_on_crontab, args=(current_time_datetime, ) ) + p3.daemon = True + p3.start() + p1.join() + p3.terminate() + p1.terminate() + + +def update_crontab(pCurrent_Time): + """ Updating crontab lists every hour + :type pCurrent_Time: time when starting crontab update + :param pCurrent_Time: datetime + + :raises: none + + :rtype: none + """ + + # Update user info now + + print('in update_crontab') + + user_ids.clear() # Example for me (Florian Kellermann) + user_crontab.clear() + user_ids.append(1770205310) + user_crontab.append("0 8 * * *") + + while True: + time_difference = datetime.datetime.now() - pCurrent_Time + if float(str(time_difference).split(':')[0]) >=1: + update_crontab(datetime.datetime.now()) + + +def update_based_on_crontab(pCurrent_Time): + current_time_ctime = time.ctime() + for i in range(len(user_crontab)): + print('tbd') + + + time.sleep(60) + def send_to_user(pText, pUser_id = 1770205310):