bug fixes and slight layout changes

This commit is contained in:
Your Name
2021-12-14 15:38:09 +00:00
parent 395a433aba
commit de3ed3e01b
5 changed files with 1187 additions and 833 deletions

View File

@@ -85,38 +85,48 @@ def updateStocks():
f.close()
stock_info = all_stocks_settings['symbols']
symbols = list(stock_info.keys())
print(symbols)
try:
valid_symbols = []
current_prices = []
opening_prices = []
for symbol in symbols:
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
intradayEndpoint = '/stock/'+ symbol+ '/intraday-prices'
querystring = '?chartIEXOnly=true&token='+iexAPIkey
try:
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
intradayEndpoint = '/stock/'+ symbol+ '/intraday-prices'
querystring = '?chartIEXOnly=true&token='+iexAPIkey
intraday_request_url = host + intradayEndpoint + querystring
intraday_response = requests.get(intraday_request_url)
for i in range(len(intraday_response.json())):
opn = intraday_response.json()[i]['open']
if opn is not None:
break
for i in range(len(intraday_response.json())-1, 0, -1):
intraday_request_url = host + intradayEndpoint + querystring
current = intraday_response.json()[i]['close']
if current is not None:
break
intraday_response = requests.get(intraday_request_url)
for i in range(len(intraday_response.json())):
opn = intraday_response.json()[i]['open']
if opn is not None:
break
for i in range(len(intraday_response.json())-1, 0, -1):
opening_prices.append(opn)
current_prices.append(current)
current = intraday_response.json()[i]['close']
if current is not None:
break
valid_symbols.append(symbol)
opening_prices.append(opn)
current_prices.append(current)
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
logf.write(str(e))
logf.write('. file: ' + fname)
logf.write('. line: ' + str(exc_tb.tb_lineno))
logf.write('. type: ' + str(exc_type))
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
stock_info = {}
@@ -124,8 +134,8 @@ def updateStocks():
for i, symbol in enumerate(symbols):
for i, symbol in enumerate(valid_symbols):
print(symbol)
stock_info[symbol] = {'current': current_prices[i], 'opening': opening_prices[i]}
@@ -337,8 +347,9 @@ def updateWeather():
all_locations = list(set(current_locations + daily_locations))
current_weathers = {}
daily_weathers = {}
current_list = []
daily_list = []
for location in all_locations:
@@ -368,7 +379,7 @@ def updateWeather():
if location in current_locations:
current_weathers[location] = current_weather
current_list.append(current_weather)
daily_weather = []
daily = r.json()['daily']
@@ -393,10 +404,17 @@ def updateWeather():
daily_weather[0]['visibility'] = current_weather['visibility']
if location in daily_locations:
daily_weathers[location] = daily_weather
daily_list.append(daily_weather)
current_weathers = {}
daily_weathers = {}
for i,loc in enumerate(current_locations):
current_weathers[loc] = current_list[i]
for i,loc in enumerate(daily_locations):
daily_weathers[loc] = daily_list[i]
all_current_settings['locations'] = current_weathers
all_daily_settings['locations'] = daily_weathers
@@ -608,10 +626,18 @@ def checkStocks(last_update, update_frequency):
return updated
def updateAll():
updateStocks()
updateCrypto()
updateForex()
updateNews()
updateSports()
updateWeather()
if __name__ == '__main__':
logf = open("log.txt", "w")
logf = open("log.txt", "a")
t = time.time()
@@ -620,6 +646,8 @@ if __name__ == '__main__':
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
@@ -651,9 +679,12 @@ if __name__ == '__main__':
t = time.time()
updateWeather()
sys.exit()
try:
while True:
if msg == 'A':
updateAll()
NY_time = datetime.now(NY_zone).replace(tzinfo=None)