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: