added sector to db caller

This commit is contained in:
Justin 2023-08-14 18:31:07 +08:00 committed by GitHub
parent 0947338073
commit 7838ac8f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -861,6 +861,13 @@ def updateMarket(api_key, logf):
except: 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": {}} 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', 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'} '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&' url = 'https://cloud.iexapis.com/stable/stock/market/overview?token=pk_aff870df1a984daa9dd43c71801c1936&'
@ -869,9 +876,11 @@ def updateMarket(api_key, logf):
mostactive = data['mostactive'] mostactive = data['mostactive']
gainers = data['gainers'] gainers = data['gainers']
losers = data['losers'] losers = data['losers']
sectors = data['sectorPerformance']
all_market_settings['losers'] = {} all_market_settings['losers'] = {}
all_market_settings['gainers'] = {} all_market_settings['gainers'] = {}
all_market_settings['mostactive'] = {} all_market_settings['mostactive'] = {}
all_sector_settings['data'] = {}
try: try:
for item in losers: for item in losers:
@ -909,13 +918,20 @@ def updateMarket(api_key, logf):
} }
except: except:
pass 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: with open('csv/market_settings.json', 'w+') as f:
json.dump(all_market_settings, 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: except:
pass pass
@ -1835,15 +1851,18 @@ if __name__ == '__main__':
closing = NY_time.replace(hour=16, minute=5, second=0, microsecond=0).replace(tzinfo=None) 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 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") market_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
last_updates['market']['time'] = market_time last_updates['market']['time'] = market_time
last_updates['market']['force'] = False 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 = Process(target = updateMarket, args = (api_key,logf))
update_process.start() update_process.start()
update_processes.append(update_process) update_processes.append(update_process)
# jokes # jokes
jokes_time = datetime.strptime(last_updates['jokes']['time'], "%d/%m/%Y %H:%M:%S") jokes_time = datetime.strptime(last_updates['jokes']['time'], "%d/%m/%Y %H:%M:%S")