diff --git a/database_caller.py b/database_caller.py index b82ca6a..c65dad6 100755 --- a/database_caller.py +++ b/database_caller.py @@ -861,6 +861,13 @@ def updateMarket(api_key, logf): except: all_market_settings = {"feature": "Gainers, Losers, Active", "speed": "medium", "speed2": "medium", "animation": "up", "percent": True, "point": True, "logos": True, "chart": False, "title": True, "lohivol": False, "categories": ["Top Gainers", "Top Losers", "Most Active"], "gainers": {}, "losers": {}, "mostactive": {}} + try: + f = open('csv/sector_settings.json', 'r') + all_sector_settings = json.load(f) + f.close() + except: + all_sector_settings = {"feature": "Sector Performance", "speed": "medium", "speed2": "medium", "animation": "up", "logos": True, "title": True, "sectors": ["Energy", "Financials", "Real Estate", "Technology"], "data": {}} + headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'} url = 'https://cloud.iexapis.com/stable/stock/market/overview?token=pk_aff870df1a984daa9dd43c71801c1936&' @@ -869,9 +876,11 @@ def updateMarket(api_key, logf): mostactive = data['mostactive'] gainers = data['gainers'] losers = data['losers'] + sectors = data['sectorPerformance'] all_market_settings['losers'] = {} all_market_settings['gainers'] = {} all_market_settings['mostactive'] = {} + all_sector_settings['data'] = {} try: for item in losers: @@ -909,13 +918,20 @@ def updateMarket(api_key, logf): } except: pass + try: + for item in sectors: + all_sector_settings['data'][item['symbol']] = { + "current": str(item['performance'] * 100), + "name": str(item['name']), + } + except: + pass with open('csv/market_settings.json', 'w+') as f: json.dump(all_market_settings, f) + with open('csv/sector_settings.json', 'w+') as f: + json.dump(all_sector_settings, f) - # all_sector_settings['sectorPerformance'] = data['sectorPerformance'] - # with open('csv/sector_settings.json', 'w+') as f: - # json.dump(all_sector_settings, f) except: pass @@ -1835,15 +1851,18 @@ if __name__ == '__main__': closing = NY_time.replace(hour=16, minute=5, second=0, microsecond=0).replace(tzinfo=None) stock_open = opening < NY_time < closing and datetime.today().weekday() <= 4 - if last_updates['market']['force'] or (diff >= update_frequencies['market'] and stock_open):# or msg == 'c': + if last_updates['market']['force'] or last_updates['sector']['force'] or (diff >= update_frequencies['market'] and stock_open):# or msg == 'c': market_time = NY_time.strftime("%d/%m/%Y %H:%M:%S") last_updates['market']['time'] = market_time last_updates['market']['force'] = False + last_updates['sector']['time'] = market_time + last_updates['sector']['force'] = False update_process = Process(target = updateMarket, args = (api_key,logf)) update_process.start() update_processes.append(update_process) + # jokes jokes_time = datetime.strptime(last_updates['jokes']['time'], "%d/%m/%Y %H:%M:%S")