black screen fix
This commit is contained in:
@@ -45,7 +45,7 @@ def updateUpdate(NY_time):
|
||||
|
||||
def updateStocks(api_key, logf):
|
||||
|
||||
print('STOCKS')
|
||||
|
||||
try:
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ def updateStocks(api_key, logf):
|
||||
f.close()
|
||||
stock_info = all_stocks_settings['symbols']
|
||||
symbols = list(stock_info.keys())
|
||||
#print(symbols)
|
||||
|
||||
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/stocks?symbols='
|
||||
|
||||
@@ -66,9 +66,7 @@ def updateStocks(api_key, logf):
|
||||
url += '&apiKey=' + api_key
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
#print(response)
|
||||
#print(dir(response))
|
||||
#print(len(data))
|
||||
|
||||
|
||||
stock_info = {}
|
||||
if len(data) > 0:
|
||||
@@ -81,11 +79,13 @@ def updateStocks(api_key, logf):
|
||||
all_stocks_settings['symbols'] = stock_info
|
||||
|
||||
|
||||
|
||||
json.dump(all_stocks_settings, open('csv/stocks_settings.json', 'w+'))
|
||||
f = open('csv/stocks_settings.json', 'w+')
|
||||
json.dump(all_stocks_settings, f)
|
||||
f.close()
|
||||
|
||||
except Exception as e:
|
||||
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -93,12 +93,13 @@ def updateStocks(api_key, logf):
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
|
||||
def updateCrypto(api_key, logf):
|
||||
|
||||
print('CRYPTO')
|
||||
#cypto_info['symbol, base'].keys() = ['current','24hr change']
|
||||
|
||||
|
||||
try:
|
||||
|
||||
|
||||
@@ -119,11 +120,10 @@ def updateCrypto(api_key, logf):
|
||||
url += bases[i] + '-' + s + ','
|
||||
url = url[:-1] #remove last comma
|
||||
url += '&apiKey=' + api_key
|
||||
#print(url)
|
||||
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
#print(url)
|
||||
#print(data)
|
||||
|
||||
|
||||
|
||||
coin_info = {}
|
||||
@@ -145,6 +145,7 @@ def updateCrypto(api_key, logf):
|
||||
|
||||
except Exception as e:
|
||||
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -152,10 +153,11 @@ def updateCrypto(api_key, logf):
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
def updateForex(api_key, logf):
|
||||
|
||||
print('FOREX')
|
||||
|
||||
|
||||
try:
|
||||
f = open('csv/forex_settings.json', 'r')
|
||||
@@ -185,7 +187,7 @@ def updateForex(api_key, logf):
|
||||
|
||||
|
||||
if len(data) > 0:
|
||||
#print(data)
|
||||
|
||||
c_dict = {}
|
||||
for sb in symbol_base:
|
||||
for d in data:
|
||||
@@ -196,9 +198,13 @@ def updateForex(api_key, logf):
|
||||
|
||||
|
||||
all_forex_settings['symbols'] = c_dict
|
||||
json.dump(all_forex_settings, open( "csv/forex_settings.json", 'w+' ))
|
||||
|
||||
f = open( "csv/forex_settings.json", 'w+' )
|
||||
json.dump(all_forex_settings, f)
|
||||
f.close()
|
||||
except Exception as e:
|
||||
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -206,6 +212,7 @@ def updateForex(api_key, logf):
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
|
||||
def updateNews(api_key, logf):
|
||||
@@ -214,10 +221,12 @@ def updateNews(api_key, logf):
|
||||
#'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news?country=GB'
|
||||
#'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/news?lang=en'
|
||||
|
||||
print('NEWS')
|
||||
|
||||
try:
|
||||
f = open('csv/news_settings.json', 'r')
|
||||
all_settings = json.load(f)
|
||||
f.close()
|
||||
|
||||
all_settings = json.load(open('csv/news_settings.json', 'r'))
|
||||
|
||||
|
||||
|
||||
@@ -234,7 +243,7 @@ def updateNews(api_key, logf):
|
||||
url += '&apiKey=' + api_key
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
#print(data)
|
||||
|
||||
if len(data) > 0:
|
||||
max_headlines = int(all_settings['num_headlines'])
|
||||
#load user settings
|
||||
@@ -247,15 +256,18 @@ def updateNews(api_key, logf):
|
||||
headline_times = [headline['publishedAt'] for headline in headlines]
|
||||
|
||||
headlines = list(zip(headline_titles, headline_sources, headline_times))
|
||||
#print(headlines)
|
||||
|
||||
all_settings['headlines'] = headlines
|
||||
|
||||
json.dump(all_settings, open('csv/news_settings.json', 'w+'))
|
||||
f = open('csv/news_settings.json', 'w+')
|
||||
json.dump(all_settings, f)
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -263,10 +275,11 @@ def updateNews(api_key, logf):
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
|
||||
def updateWeather(api_key, logf):
|
||||
print('WEATHER')
|
||||
|
||||
max_cities = 30
|
||||
|
||||
try:
|
||||
@@ -283,15 +296,14 @@ def updateWeather(api_key, logf):
|
||||
current_locations = list(all_current_settings['locations'].keys())
|
||||
daily_locations = list(all_daily_settings['locations'].keys())
|
||||
|
||||
print(current_locations, daily_locations)
|
||||
all_locations = list(set(current_locations + daily_locations))
|
||||
print(all_locations)
|
||||
|
||||
|
||||
|
||||
|
||||
current_weathers = {}
|
||||
daily_weathers = {}
|
||||
|
||||
currents = []
|
||||
dailys = []
|
||||
|
||||
|
||||
for location in all_locations:
|
||||
@@ -320,7 +332,8 @@ def updateWeather(api_key, logf):
|
||||
current_weather['rain_chance'] = r.json()['hourly'][0]['pop']
|
||||
|
||||
|
||||
currents.append(current_weather)
|
||||
if location in current_locations:
|
||||
current_weathers[location] = current_weather
|
||||
|
||||
daily_weather = []
|
||||
daily = r.json()['daily']
|
||||
@@ -344,35 +357,24 @@ def updateWeather(api_key, logf):
|
||||
daily_weather[0]['wind_direction'] = current_weather['wind_direction']
|
||||
daily_weather[0]['visibility'] = current_weather['visibility']
|
||||
|
||||
dailys.append(daily_weather)
|
||||
if location in daily_locations:
|
||||
daily_weathers[location] = daily_weather
|
||||
|
||||
current_weathers = {}
|
||||
daily_weathers = {}
|
||||
|
||||
|
||||
|
||||
for l in current_locations:
|
||||
for i,loc in enumerate(all_locations):
|
||||
if l == loc:
|
||||
current_weathers[location] = currents[i]
|
||||
|
||||
for l in daily_locations:
|
||||
for i,loc in enumerate(all_locations):
|
||||
if l == loc:
|
||||
daily_weathers[location] = dailys[i]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
all_current_settings['locations'] = current_weathers
|
||||
all_daily_settings['locations'] = daily_weathers
|
||||
#print(all_current_settings, all_daily_settings)
|
||||
json.dump( all_current_settings, open( "csv/current_weather.json", 'w+' ))
|
||||
json.dump( all_daily_settings, open( "csv/daily_weather.json", 'w+' ))
|
||||
f = open( "csv/current_weather.json", 'w+' )
|
||||
json.dump( all_current_settings, f)
|
||||
f.close()
|
||||
|
||||
f = open( "csv/daily_weather.json", 'w+' )
|
||||
json.dump( all_daily_settings, f)
|
||||
f.close()
|
||||
|
||||
except Exception as e:
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -380,15 +382,15 @@ def updateWeather(api_key, logf):
|
||||
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])))
|
||||
|
||||
logf.close()
|
||||
|
||||
def updateLeagueTables(api_key, logf):
|
||||
print('LEAGUE TABLES')
|
||||
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/sports?stats='
|
||||
try:
|
||||
f = open('csv/league_tables.json', 'r')
|
||||
all_settings = json.load(f)
|
||||
#print(all_settings['leagues'].keys())
|
||||
|
||||
f.close()
|
||||
|
||||
leagues = all_settings['leagues'].keys()
|
||||
@@ -407,12 +409,11 @@ def updateLeagueTables(api_key, logf):
|
||||
all_data = r.json()
|
||||
|
||||
|
||||
#print('key', [all_data[i].keys() for i in range(len(all_data))])
|
||||
#print('key', all_data.keys())
|
||||
|
||||
for i,l in enumerate(all_data):
|
||||
#print(l)
|
||||
|
||||
league = list(l.keys())[0]
|
||||
#print('league', league, list(l.keys()))
|
||||
|
||||
|
||||
teams = []
|
||||
|
||||
@@ -434,10 +435,13 @@ def updateLeagueTables(api_key, logf):
|
||||
leagues_info[league.upper()] = teams
|
||||
|
||||
all_settings['leagues'] = leagues_info
|
||||
#print(all_settings['leagues'].keys())
|
||||
json.dump(all_settings, open( "csv/league_tables.json".format(league), 'w+' ))
|
||||
f = open( "csv/league_tables.json".format(league), 'w+' )
|
||||
json.dump(all_settings, f)
|
||||
|
||||
f.close()
|
||||
except Exception as e:
|
||||
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -445,10 +449,11 @@ def updateLeagueTables(api_key, logf):
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
|
||||
def updateLeagueEvents(api_key, time, logf):
|
||||
print('LEAGUE EVENTS', time)
|
||||
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/sports?{}='.format(time)
|
||||
|
||||
if time == 'past':
|
||||
@@ -465,7 +470,7 @@ def updateLeagueEvents(api_key, time, logf):
|
||||
|
||||
try:
|
||||
all_settings = json.load(f)
|
||||
#print(all_settings['leagues'].keys())
|
||||
|
||||
f.close()
|
||||
leagues = all_settings['leagues'].keys()
|
||||
leagues_info = {}
|
||||
@@ -483,10 +488,6 @@ def updateLeagueEvents(api_key, time, logf):
|
||||
|
||||
all_data = r.json()
|
||||
|
||||
#print(all_data)
|
||||
|
||||
|
||||
|
||||
for league in all_data.keys():
|
||||
events = []
|
||||
for d in all_data[league]:
|
||||
@@ -512,11 +513,12 @@ def updateLeagueEvents(api_key, time, logf):
|
||||
events.append(event)
|
||||
leagues_info[league.upper()] = events
|
||||
all_settings['leagues'] = leagues_info
|
||||
#print(all_settings['leagues'].keys())
|
||||
|
||||
json.dump(all_settings, open( "csv/{}_games.json".format(time), 'w+' ))
|
||||
|
||||
f = open( "csv/{}_games.json".format(time), 'w+' )
|
||||
json.dump(all_settings, f)
|
||||
f.close()
|
||||
except Exception as e:
|
||||
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -524,6 +526,7 @@ def updateLeagueEvents(api_key, time, logf):
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
|
||||
def updateSports(api_key, logf):
|
||||
@@ -541,7 +544,7 @@ def updateSports(api_key, logf):
|
||||
def checkStocks(last_update, update_frequency):
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
opening = NY_time.replace(hour=9, minute=30, second=0, microsecond=0).replace(tzinfo=None)
|
||||
closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0).replace(tzinfo=None)
|
||||
closing = NY_time.replace(hour=16, minute=5, second=0, microsecond=0).replace(tzinfo=None)
|
||||
|
||||
|
||||
f = open('csv/stocks_settings.json', 'r')
|
||||
@@ -603,7 +606,7 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
|
||||
update_frequencies = {'stocks':1, 'crypto':5, 'forex':60, 'news':120, 'weather': 120, 'sports': 1440} #minutes
|
||||
update_frequencies = {'stocks':2, 'crypto':5, 'forex':60, 'news':120, 'weather': 120, 'sports': 1440} #minutes
|
||||
|
||||
NY_zone = pytz.timezone('America/New_York')
|
||||
CET_zone = pytz.timezone('EST')
|
||||
@@ -630,6 +633,7 @@ if __name__ == '__main__':
|
||||
weather_key = api_keys[1].strip()
|
||||
except Exception as e:
|
||||
weather_key = False
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -637,6 +641,7 @@ if __name__ == '__main__':
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
|
||||
|
||||
@@ -681,7 +686,7 @@ if __name__ == '__main__':
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
opening = NY_time.replace(hour=9, minute=30, second=0, microsecond=0).replace(tzinfo=None)
|
||||
closing = NY_time.replace(hour=16, minute=0, 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
|
||||
|
||||
if last_updates['stocks']['force'] or (diff >= update_frequencies['stocks'] and stock_open):# or msg == 's':
|
||||
@@ -834,13 +839,14 @@ if __name__ == '__main__':
|
||||
process.join()
|
||||
process.terminate()
|
||||
update_processes.remove(process)
|
||||
print('Number active database caller processes', len(update_processes))
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
|
||||
logf = open('log.txt', "a")
|
||||
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))
|
||||
@@ -848,7 +854,9 @@ if __name__ == '__main__':
|
||||
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])))
|
||||
logf.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user