From 5cf29c80e40685e515795eec04f1d14ade929404 Mon Sep 17 00:00:00 2001 From: Neythen Treloar Date: Sun, 6 Mar 2022 10:04:03 +0000 Subject: [PATCH] stock updates only in NY stock exchange hours --- database_caller.py | 10 ++++++++-- stockTicker.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/database_caller.py b/database_caller.py index 1baf394..eccba9c 100755 --- a/database_caller.py +++ b/database_caller.py @@ -658,7 +658,13 @@ if __name__ == '__main__': stock_time = datetime.strptime(last_updates['stocks']['time'], "%d/%m/%Y %H:%M:%S") stock_frequency = update_frequencies['stocks'] diff = (NY_time - stock_time).total_seconds()/60 #minutes - if last_updates['stocks']['force'] or diff >= update_frequencies['stocks']:# or msg == 's': + + NY_time = datetime.now(NY_zone).replace(tzinfo=None) + opening = NY_time.replace(hour=9, minute=30, second=0, microsecond=0).replace(tzinfo=None) + closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0).replace(tzinfo=None) + stock_open = opening < NY_time < closing and datetime.today().weekday() <= 4 + + if last_updates['stocks']['force'] or (diff >= update_frequencies['stocks'] and stock_open):# or msg == 's': stock_time = NY_time.strftime("%d/%m/%Y %H:%M:%S") last_updates['stocks']['time'] = stock_time last_updates['stocks']['force'] = False @@ -762,7 +768,7 @@ if __name__ == '__main__': process.join() process.terminate() update_processes.remove(process) - print('Number active processes', len(update_processes)) + print('Number active database caller processes', len(update_processes)) time.sleep(10) diff --git a/stockTicker.py b/stockTicker.py index 6233e10..e49c791 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -2754,7 +2754,7 @@ if __name__ == '__main__': #stock_ticker.process_msg('*') #time.sleep(8) - stock_ticker.process_msg('-') + #stock_ticker.process_msg('-') #stock_ticker.process_msg('W') #stock_ticker.process_msg('A')