From 39f0496b9224ef8c28159bd4a0039e253e6d264c Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 24 Jul 2023 17:32:07 +0800 Subject: [PATCH] added try and except for prepost --- database_caller.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/database_caller.py b/database_caller.py index 76ae2cb..9c359cc 100755 --- a/database_caller.py +++ b/database_caller.py @@ -282,31 +282,33 @@ def updateStocksPrePost(api_key, logf): if len(prepost_data) > 0: for symbol in symbols: - for stock in prepost_data: - if stock['symbol'] == symbol: - stock_info[stock['symbol']] = {"time_now":time_now} - try: - stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['preMarketPrice'], + try: + for stock in prepost_data: + if stock['symbol'] == symbol: + stock_info[stock['symbol']] = {"time_now":time_now} + try: + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['preMarketPrice'], 'prechange': '%.2f' % stock['preMarketChange'], 'prepercent': '%.2f' % stock['preMarketChangePercent']} - except: - try: - stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['postMarketPrice'], + except: + try: + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['postMarketPrice'], 'prechange': '%.2f' % 0, 'prepercent': '%.2f' % 0} - except: - stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['regularMarketPrice'], + except: + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Pre-market'] = {'preprice': '%.2f' % stock['regularMarketPrice'], 'prechange': '%.2f' % 0, 'prepercent': '%.2f' % 0} - try: - stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Post-market'] = {'postprice': '%.2f' % stock['postMarketPrice'], + try: + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Post-market'] = {'postprice': '%.2f' % stock['postMarketPrice'], 'postchange': '%.2f' % stock['postMarketChange'], 'postpercent': '%.2f' % stock['postMarketChangePercent']} - except: - stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Post-market'] = {'postprice': '%.2f' % stock['regularMarketPrice'], + except: + stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')]['Post-market'] = {'postprice': '%.2f' % stock['regularMarketPrice'], 'postchange': '%.2f' % 0, 'postpercent': '%.2f' % 0} - + except: + pass all_stocks_settings['symbols'] = stock_info with open('csv/prepost_settings.json', 'w+') as f: