Merge pull request #9 from fin-tic/dev

Version 1.0.1 release
This commit is contained in:
Neythen Treloar 2022-04-11 18:38:41 +01:00 committed by GitHub
commit 0c8d1d6b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 500 additions and 350 deletions

View File

@ -35,7 +35,9 @@ rm csv/system_info.json
echo "$str" >> csv/system_info.json
sudo chmod 777 csv/system_info.json

View File

@ -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:
all_settings = json.load(open('csv/news_settings.json', 'r'))
try:
f = open('csv/news_settings.json', 'r')
all_settings = json.load(f)
f.close()
@ -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:
@ -349,14 +362,18 @@ def updateWeather(api_key, logf):
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))
@ -365,13 +382,16 @@ def updateWeather(api_key, logf):
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()
@ -390,12 +410,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 = []
@ -417,10 +436,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))
@ -428,10 +450,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':
@ -448,7 +471,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 = {}
@ -466,10 +489,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]:
@ -495,11 +514,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))
@ -507,6 +527,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):
@ -613,6 +634,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))
@ -620,6 +642,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()
@ -817,13 +840,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))
@ -831,6 +855,8 @@ 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()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 706 B

257
server.py
View File

@ -23,7 +23,7 @@ import copy
import urllib.request
import sys
#stock_ticker = StockTicker()
#print('API CALLER NOT STARTED')
#open('log.txt', 'w').close() #wipe logs
@ -42,13 +42,16 @@ displaying_screensaver = False
uploading = False
screensaver_p = None
ticker_stopped = False
professional = json.load(open('csv/display_settings.json', 'r'))[0] == "Professional"
f = open('csv/display_settings.json', 'r')
professional = json.load(f)[0] == "Professional"
f.close()
command = 300
tickerList = 0
DelayTime = 20
LastCommand = ''
speedTime = 25 #print('save')
speedTime = 25
LOGO_FOLDER = 'logos/'
CSV_FOLDER = 'csv/new/'
@ -57,7 +60,15 @@ ALLOWED_EXTENSIONS = {'csv', 'png'}
ticker = pexpect.spawn("sudo -E python3 stockTicker.py")
time.sleep(2) # give the ticker time to initialise
system_info = json.load(open('csv/system_info.json'))
f = open('csv/system_info.json', 'w')
try:
system_info = json.load(f)
except Exception as e:
system_info = {"update_available": False, "first_boot": False}
json.dump(system_info, f)
f.close()
ticker.sendline('*') # run startup gif by default
time.sleep(8)
@ -65,7 +76,9 @@ if system_info['first_boot']: # let startup message display
ticker.sendline('-')
system_info['first_boot'] = False
json.dump(system_info, open('csv/system_info.json', 'w'))
f = open('csv/system_info.json', 'w')
json.dump(system_info,f)
f.close()
else:
ticker.sendline('A') # run by default
@ -94,16 +107,22 @@ def index():
global professional
feature_settings = json.load(open('csv/display_settings.json', 'r'))
f = open('csv/display_settings.json', 'r')
feature_settings = json.load(f)
f.close()
print('professional',professional)
if not professional:
currently_displaying = json.load(open('csv/display_settings.json', 'r'))[1]
f = open('csv/display_settings.json', 'r')
currently_displaying = json.load(f)[1]
f.close()
not_displaying = [f for f in all_features if f not in currently_displaying[0]]
elif professional:
currently_displaying = json.load(open('csv/display_settings.json', 'r'))[1]
f = open('csv/display_settings.json', 'r')
currently_displaying = json.load(f)[1]
f.close()
not_displaying = [f for f in all_features if f not in currently_displaying[0] and f not in currently_displaying[1]]
with open('api_keys.txt', 'r') as f:
@ -117,21 +136,64 @@ def index():
logos_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos')
LogoList = os.listdir(logos_path)
stocks_settings = json.load(open('csv/stocks_settings.json', 'r'))
crypto_settings = json.load(open('csv/crypto_settings.json', 'r'))
forex_settings = json.load(open('csv/forex_settings.json', 'r'))
current_weather= json.load(open('csv/current_weather.json', 'r'))
daily_weather = json.load(open('csv/daily_weather.json', 'r'))
news_settings = json.load(open('csv/news_settings.json', 'r'))
upcoming_games = json.load(open('csv/upcoming_games.json', 'r'))
live_games = json.load(open('csv/live_games.json', 'r'))
past_games = json.load(open('csv/past_games.json', 'r'))
team_stats = json.load(open('csv/league_tables.json', 'r'))
image_settings = json.load(open('csv/image_settings.json', 'r'))
GIF_settings = json.load(open('csv/GIF_settings.json', 'r'))
message_settings = json.load(open('csv/message_settings.json', 'r'))
general_settings = json.load(open('csv/general_settings.json', 'r'))
system_info = json.load(open('csv/system_info.json', 'r'))
f = open('csv/stocks_settings.json', 'r')
stocks_settings = json.load(f)
f.close()
f= open('csv/crypto_settings.json', 'r')
crypto_settings = json.load(f)
f.close()
f = open('csv/forex_settings.json', 'r')
forex_settings = json.load(f)
f.close()
f = open('csv/current_weather.json', 'r')
current_weather= json.load(f)
f.close()
f = open('csv/daily_weather.json', 'r')
daily_weather = json.load(f)
f.close()
f = open('csv/news_settings.json', 'r')
news_settings = json.load(f)
f.close()
f = open('csv/upcoming_games.json', 'r')
upcoming_games = json.load(f)
f.close()
f = open('csv/live_games.json', 'r')
live_games = json.load(f)
f.close()
f = open('csv/past_games.json', 'r')
past_games = json.load(f)
f.close()
f = open('csv/league_tables.json', 'r')
team_stats = json.load(f)
f.close()
f = open('csv/image_settings.json', 'r')
image_settings = json.load(f)
f.close()
f = open('csv/GIF_settings.json', 'r')
GIF_settings = json.load(f)
f.close()
f = open('csv/message_settings.json', 'r')
message_settings = json.load(f)
f.close()
f = open('csv/general_settings.json', 'r')
general_settings = json.load(f)
f.close()
try: # incase this doesnt exist
api_keys = api_key2[1]
except:
@ -166,15 +228,15 @@ def index():
'wifi_SSID':wifi_SSID
}
#print('database caller:', api_caller.isalive())
return render_template('index.html', **templateData)
def save_displaying(input_settings):
#print('save')
global professional
print('save_displaying_input:', input_settings)
all_settings = ['Stocks', 'Crypto', 'Forex', 'Current Weather', 'Daily Forecast', 'News', 'Sports (Upcoming Games)', 'Sports (Past Games)',
'Sports (Live Games)', 'Sports (Team Stats)', 'Custom Images', 'Custom GIFs', 'Custom Messages']
professional = len(input_settings) == 2
@ -196,7 +258,7 @@ def save_displaying(input_settings):
s = "Professional" if professional else "Standard"
display_settings = [s] + [input_settings]
print(display_settings)
with open('csv/display_settings.json', 'w+') as f:
json.dump(list(display_settings), f)
@ -230,16 +292,17 @@ def start():
@app.route("/stop")
def stop():
print('stop')
global displaying_screensaver
global ticker
#global api_caller
global professional
global ticker_stopped
ticker.sendline('K')
if not displaying_screensaver:
ticker.sendline('K')
time.sleep(0.1) # give time for leds to turn off
ticker.close()
else:
@ -263,10 +326,20 @@ def stop():
@app.route("/update", methods=['PUT','POST'])
def update():
system_info = json.load(open('csv/system_info.json', 'r'))
system_info["update_available"] = False
json.dump(system_info, open('csv/system_info.json', 'w+'))
f = open('csv/system_info.json', 'w+')
try:
system_info = json.load(f)
except Exception as e:
system_info = {"update_available": False, "first_boot": False}
system_info['update_available'] = False
json.dump(system_info, f)
f.close()
os.system("./update.sh")
os.system("sudo reboot now")
return index()
@ -278,13 +351,13 @@ def restart():
@app.route("/reset")
def reset():
print('reset')
os.system("sudo ./setup_config_files.sh")
return index()
@app.route("/save", methods = ['PUT', 'POST', 'GET'])
def save():
print('save')
global uploading
@ -294,7 +367,6 @@ def save():
input_settings = json.loads(data)
print(input_settings)
save_displaying(input_settings['displaying'])
@ -315,10 +387,9 @@ def save():
images = request.files
names = list(request.files.keys())
print(names)
for name in names:
print(name)
images[name].save('user_uploads/' +name)
@ -332,7 +403,7 @@ def save():
# saves files uploaded to the webpage for images and GIFs
@app.route("/upload", methods = ['PUT', 'POST', 'GET'])
def upload():
print('upload')
global uploading
uploading = True
try:
@ -344,15 +415,21 @@ def upload():
images[name].save('user_uploads/' +name)
except Exception as e:
#print(e)
uploading = False
return index()
def remove_old_uploads():
#remove old files
image_settings = json.load(open('csv/image_settings.json', 'r'))
GIF_settings = json.load(open('csv/GIF_settings.json', 'r'))
f = open('csv/image_settings.json', 'r')
image_settings = json.load(f)
f.close()
f = open('csv/GIF_settings.json', 'r')
GIF_settings = json.load(f)
f.close()
for filename in os.listdir('user_uploads'):
if filename not in image_settings['images'] and filename not in GIF_settings['images']:
os.remove('user_uploads/'+filename)
@ -365,15 +442,17 @@ def brightness():
data= request.data.decode('utf-8')
settings = json.loads(data)
print(settings)
brightness =settings['brightness']
ticker.sendline(str(int(brightness)-1))
general_settings = json.load(open('csv/general_settings.json', 'r'))
f = open('csv/general_settings.json', 'r')
general_settings = json.load(f)
f.close()
general_settings['brightness'] = int(brightness)
json.dump(general_settings, open('csv/general_settings.json', 'w+'))
f = open('csv/general_settings.json', 'w+')
json.dump(general_settings, f)
f.close()
return index()
@ -388,7 +467,7 @@ def edit_wpa_sup(country, ssid, pwd):
#remove this line to append to end instead of overwriting all networks
wpa_lines = wpa_lines[0:3]
print(wpa_lines)
# create new file from scratch
wpa_lines = []
@ -404,7 +483,7 @@ def edit_wpa_sup(country, ssid, pwd):
wpa_lines.append('}\n')
wpa_string = ''.join(wpa_lines)
print(wpa_string)
current_wpa = open('/etc/wpa_supplicant/wpa_supplicant.conf', 'w+')
current_wpa.write(wpa_string)
@ -413,17 +492,20 @@ def edit_wpa_sup(country, ssid, pwd):
def set_wifi():
data= request.data.decode('utf-8')
print(str(data))
settings = json.loads(data)
country = settings['country'].upper()
ssid = settings['ssid']
pwd = settings['pwd']
general_settings = json.load(open('csv/general_settings.json', 'r'))
f = open('csv/general_settings.json', 'r')
general_settings = json.load(f)
f.close()
general_settings['country_code'] = country
json.dump(general_settings, open('csv/general_settings.json', 'w+'))
f = open('csv/general_settings.json', 'w+')
json.dump(general_settings, f)
f.close()
edit_wpa_sup(country, ssid, pwd)
# resstart netoworking
@ -445,14 +527,14 @@ def set_wifi():
#return True
#except subprocess.CalledProcessError:
# grep did not match any lines
#print("No wireless networks connected")
#return False
def edit_hosts(hostname):
current_hosts = open('/etc/hosts')
hosts_lines = current_hosts.readlines()
print(hosts_lines[5])
hosts_lines[5] = '127.0.1.1 {}'.format(hostname)
@ -468,16 +550,20 @@ def hostname():
data= request.data.decode('utf-8')
settings = json.loads(data)
hostname = settings['hostname']
print('hostname', hostname)
edit_hosts(hostname)
os.system("sudo hostnamectl set-hostname {}".format(hostname))
os.system("sudo systemctl restart avahi-daemon")
general_settings = json.load(open('csv/general_settings.json', 'r'))
f = open('csv/general_settings.json', 'r')
general_settings = json.load(f)
f.close()
general_settings['hostname'] = hostname
json.dump(general_settings, open('csv/general_settings.json', 'w+'))
f = open('csv/general_settings.json', 'w+')
json.dump(general_settings, f)
f.close()
return index()
@ -489,14 +575,14 @@ def saveWeatherAPIKey():
settings = json.loads(data)
key = settings['api_key']
print(key)
with open('./api_keys.txt') as f:
lines = f.readlines()
if len(lines) == 1:
lines.append(str(key))
elif len(lines) == 2:
lines[1] = str(key)
print(lines)
with open('./api_keys.txt', 'w') as f:
for line in lines:
f.write(line)
@ -565,7 +651,7 @@ def save_trade_settings(input_settings):
filename = input_settings['feature'].lower() + '_settings.json'
f = open('csv/' + filename, 'r')
current_settings = json.load(f)
print(input_settings)
f.close()
current_settings['speed'] = input_settings['speed'].lower()
@ -598,13 +684,14 @@ def save_trade_settings(input_settings):
def save_weather_settings(input_settings):
print(input_settings)
filename = 'current_weather.json' if input_settings['feature'] == 'Current Weather' else 'daily_weather.json'
print(filename)
current_settings = json.load(open('csv/' + filename, 'r'))
f = open('csv/' + filename, 'r')
current_settings = json.load(f)
f.close()
current_settings['speed'] = input_settings['speed'].lower()
current_settings['speed2'] = input_settings['speed2'].lower()
@ -625,7 +712,9 @@ def save_weather_settings(input_settings):
'''
current_settings = combine_dict(current_settings, input_settings['locations'], 'locations')
json.dump(current_settings, open('csv/' + filename, 'w+'))
f = open('csv/' + filename, 'w+')
json.dump(current_settings, f)
f.close()
#api_caller.sendline('w')
f = open('csv/last_updates.json', 'r')
@ -641,10 +730,11 @@ def save_weather_settings(input_settings):
def save_news_settings(input_settings):
filename = 'news_settings.json'
f = open('csv/' + filename, 'r')
current_settings = json.load(f)
f.close()
current_settings = json.load(open('csv/' + filename, 'r'))
print(current_settings)
current_settings['speed'] = input_settings['speed'].lower()
current_settings['speed2'] = input_settings['speed2'].lower()
@ -658,9 +748,10 @@ def save_news_settings(input_settings):
print(current_settings)
json.dump(current_settings, open('csv/' + filename, 'w+'))
f = open('csv/' + filename, 'w+')
json.dump(current_settings, f)
f.close()
#api_caller.sendline('n')
f = open('csv/last_updates.json', 'r')
last_updates = json.load(f)
@ -689,7 +780,9 @@ def save_sports_settings(input_settings):
filename = 'league_tables.json'
update_key = 'sports_t'
current_settings = json.load(open('csv/' + filename, 'r'))
f = open('csv/' + filename, 'r')
current_settings = json.load(f)
f.close()
current_settings['speed'] = input_settings['speed'].lower()
current_settings['speed2'] = input_settings['speed2'].lower()
@ -699,7 +792,9 @@ def save_sports_settings(input_settings):
current_settings = combine_dict(current_settings, input_settings['leagues'], 'leagues')
json.dump(current_settings, open('csv/' + filename, 'w+'))
f = open('csv/' + filename, 'w+')
json.dump(current_settings, f)
f.close()
#api_caller.sendline('S')
f = open('csv/last_updates.json', 'r')
@ -726,29 +821,31 @@ def save_image_settings(input_settings):
del current_settings['feature']
json.dump(current_settings, open('csv/' + filename, 'w+'))
f = open('csv/' + filename, 'w+')
json.dump(current_settings, f)
f.close()
remove_old_uploads()
def save_message_settings(input_settings):
current_settings = json.load(open('csv/message_settings.json', 'r'))
f = open('csv/message_settings.json', 'r')
current_settings = json.load(f)
f.close()
new_settings = copy.deepcopy(input_settings)
print(current_settings)
print()
print(input_settings)
print()
for i,IS in enumerate(input_settings['messages']):
# check if this is in current_settings
for CS in current_settings['messages']:
if IS['name'] == CS['name']:
new_settings['messages'][i] = CS
print(CS)
break
print(new_settings)
json.dump(new_settings, open('csv/message_settings.json', 'w+'))
f = open('csv/message_settings.json', 'w+')
json.dump(new_settings, f)
f.close()

View File

@ -57,10 +57,10 @@ class StockTicker():
options.chain_length = 2
options.parallel = 1
options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat'
options.gpio_slowdown = 1
options.gpio_slowdown = 2
options.brightness = self.brightness
self.matrix = RGBMatrix(options = options)
print(dir(self.matrix))
#sys.exit()
self.points = True # display crypto change in points or percent
@ -286,7 +286,7 @@ class StockTicker():
return kill
def updateMultiple(self, options):
print('options', options)
for option in options:
@ -344,7 +344,9 @@ class StockTicker():
update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],))
update_process.start()
settings = json.load(open(self.JSONs[options[(i) % len(options)]]))
f = open(self.JSONs[options[(i) % len(options)]])
settings = json.load(f)
f.close()
self.set_delay(settings['speed'])
animation = settings['animation'].lower()
@ -615,7 +617,7 @@ class StockTicker():
kind, content, delay = row
delays.append(delay)
kinds.append(kind)
print(kind, content, delay)
if kind == 'text':
images.append(self.textImage(content, font, 255, 255, 0, True, w_buff = 50))
elif kind == 'image':
@ -971,13 +973,15 @@ class StockTicker():
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
finalDisplayImage = self.stitchImage(image_list)
@ -1042,13 +1046,15 @@ class StockTicker():
image_list.append(self.blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
finalDisplayImage = self.stitchImage(image_list)
self.blank = Image.new('RGB', (10, 32))
@ -1116,28 +1122,36 @@ class StockTicker():
image_list.append(new_im)
except Exception as e:
print(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))
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])))
logf.close()
image_list.append(midFrame)
image_list.append(self.blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
finalDisplayImage = self.stitchImage(image_list)
return finalDisplayImage
def getForexProfessional(self):
print('forex prof')
self.blank = Image.new('RGB', (0, 16))
f = open('csv/forex_settings.json', 'r')
all_forex_settings = json.load(f)
@ -1163,9 +1177,6 @@ class StockTicker():
current = float(forex_settings[sb]['current'])
change = float(forex_settings[sb]['24hr_change'])
arrow, change = self.getArrow(change, professional = True)
@ -1201,23 +1212,30 @@ class StockTicker():
image_list.append(new_im)
except Exception as e:
print(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))
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])))
logf.close()
image_list.append(midFrame)
image_list.append(self.blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
finalDisplayImage = self.stitchImage(image_list)
self.blank = Image.new('RGB', (10, 32))
@ -1256,7 +1274,7 @@ class StockTicker():
percent_change = '%.2f' % abs(float(info['percent_change'])) + '%'
point_change = '%.2f' % abs(change)
print(percent_change, point_change)
current = '%.2f' % float(info['current']) #TEXT
@ -1279,7 +1297,7 @@ class StockTicker():
logo = self.openImage(os.path.join(logos_path, ticker + '.png'))
stitchedStock = self.stitchImage([logo,midFrame])
except Exception as e:
print(str(e))
stitchedStock = midFrame
else:
stitchedStock = midFrame
@ -1289,13 +1307,16 @@ class StockTicker():
image_list.append(self.blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
@ -1373,14 +1394,15 @@ class StockTicker():
image_list.append(self.blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
finalDisplayImage = self.stitchImage(image_list)
@ -1390,7 +1412,10 @@ class StockTicker():
def getNewsImage(self):
all_settings = json.load(open('csv/news_settings.json', 'r'))
f = open('csv/news_settings.json', 'r')
all_settings = json.load(f)
f.close()
if all_settings['title']:
title_img = self.openImage('feature_titles/news.png')
@ -1455,21 +1480,24 @@ class StockTicker():
image_list.append(img)
image_list.append(self.blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
news_image = self.stitchImage(image_list)
return news_image
def getNewsProfessional(self):
all_settings = json.load(open('csv/news_settings.json', 'r'))
f = open('csv/news_settings.json', 'r')
all_settings = json.load(f)
f.close()
if all_settings['title']:
title_img = self.openImage('feature_titles/small_feature_titles/news.png')
@ -1541,13 +1569,15 @@ class StockTicker():
image_list.append(img)
image_list.append(blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
news_image = self.stitchImage(image_list)
return news_image
@ -1558,11 +1588,16 @@ class StockTicker():
filepath = 'csv/{}_games.json'.format(time)
else:
print(time)
filepath = 'csv/upcoming_games.json'
all_settings = json.load(open(filepath, 'r'))
f = open(filepath, 'r')
all_settings = json.load(f)
f.close()
title_img = self.openImage('feature_titles/sports_'+ time + '.png')
if all_settings['title']:
title_img = self.openImage('feature_titles/sports_{}.png'.format(time))
@ -1578,8 +1613,6 @@ class StockTicker():
for league in leagues:
try:
x_offset = 0
img = Image.new('RGB', (10000, 32))
league_info = leagues_info[league]
@ -1597,7 +1630,6 @@ class StockTicker():
large_font = ImageFont.load("./fonts/9x18B.pil")
sports_info = self.readSportsCSV(league)
print(sports_info)
buff_size = 25
@ -1611,8 +1643,6 @@ class StockTicker():
dateEvent = match['date'].replace('-', '.')
#rond = match['round']
try:
@ -1700,14 +1730,15 @@ class StockTicker():
imgs.append(img)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
@ -1715,8 +1746,10 @@ class StockTicker():
def getLeagueTableImage(self, league = False):
f = open('csv/league_tables.json', 'r')
all_settings = json.load(f)
f.close()
all_settings = json.load(open('csv/league_tables.json', 'r'))
leagues_info = all_settings['leagues']
@ -1766,7 +1799,15 @@ class StockTicker():
x_offset += logo.size[0] + 2
except Exception as e:
print('no logo for:', team['name'])
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))
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])))
logf.close()
name_timage = self.textImage(team['name'], med_font, r = 255, g = 255, b = 0)
@ -1799,18 +1840,31 @@ class StockTicker():
imgs.append(img)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
return self.stitchImage(imgs)
def convertTemp(self,temp, setting):
if setting == 'kelvin':
temp = temp+ 273.15
elif setting == 'fahrenheit':
temp = temp*9/5 + 32
return temp
def getTodayWeatherImage(self):
all_settings = json.load(open('csv/current_weather.json', 'r'))
f = open('csv/current_weather.json', 'r')
all_settings = json.load(f)
f.close()
if all_settings['title']:
title_img = self.openImage('feature_titles/weather.png')
@ -1840,21 +1894,21 @@ class StockTicker():
weather_dir = './logos/weather_icons'
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
temp = current_weather['temp']
feels_temp = current_weather['feels_like']
if all_settings['temp'] == 'kelvin':
temp = current_weather['temp'] + 273.15
elif all_settings['temp'] == 'fahrenheit':
feels_temp = current_weather['feels_like']*9/5 + 32
temp = current_weather['temp']*9/5 + 32
temp = self.convertTemp(current_weather['temp'], all_settings['temp'])
feels_temp = self.convertTemp(current_weather['feels_like'], all_settings['temp'])
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
deg_img = self.textImage('o', small_font)
main = current_weather['main_weather']
main_img = self.textImage(main.upper(), small_font)
feels_img = self.textImage('Feels like:'.upper() + str("{0:.0f}".format(feels_temp)), small_font)
min_img = self.textImage( "{0:.0f}".format(current_weather['min_temp']), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(current_weather['max_temp']), small_font, r=255, g=0, b=0)
min_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['min_temp'], all_settings['temp'])), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['max_temp'], all_settings['temp'])), small_font, r=255, g=0, b=0)
hum_img = Image.open(weather_dir + '/humidity.png')
htext_img = self.textImage(str(current_weather['humidity']) + '%', small_font)
uv_img = Image.open(weather_dir + '/uv.png')
@ -1935,19 +1989,24 @@ class StockTicker():
imgs.append(img)
imgs.append(self.blank)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
return self.stitchImage(imgs)
def getTodayWeatherProfessional(self):
all_settings = json.load(open('csv/current_weather.json', 'r'))
f = open('csv/current_weather.json', 'r')
all_settings = json.load(f)
f.close()
if all_settings['title']:
title_img = self.openImage('feature_titles/small_feature_titles/weather.png')
@ -2016,11 +2075,8 @@ class StockTicker():
temp = current_weather['temp']
if all_settings['temp'] == 'kelvin':
temp = current_weather['temp'] + 273.15
elif all_settings['temp'] == 'fahrenheit':
temp = current_weather['temp']*9/5 + 32
temp = self.convertTemp(current_weather['temp'], all_settings['temp'])
temp_img = self.textImage(str("{0:.0f}".format(temp)), font)
img.paste(temp_img, (x_offset,3))
@ -2032,10 +2088,10 @@ class StockTicker():
x_offset += deg_img.size[0] -2
min_img = self.textImage( "{0:.0f}".format(current_weather['min_temp']), small_font, r=0, g=0, b=255)
min_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['min_temp'], all_settings['temp'])), small_font, r=0, g=0, b=255)
img.paste(min_img, (x_offset+2, 2))
max_img = self.textImage( "{0:.0f}".format(current_weather['max_temp']), small_font, r=255, g=0, b=0)
max_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['max_temp'], all_settings['temp'])), small_font, r=255, g=0, b=0)
img.paste(max_img, (x_offset+2, 8))
x_offset += max_img.size[0] + 2
@ -2077,13 +2133,15 @@ class StockTicker():
image_list.append(img)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
return self.stitchImage(image_list)
def getDailyWeatherImageAlt(self):
@ -2230,8 +2288,10 @@ class StockTicker():
def getDailyWeatherImage(self):
f = open('csv/daily_weather.json', 'r')
all_settings = json.load(f)
f.close()
all_settings = json.load(open('csv/daily_weather.json', 'r'))
if all_settings['title']:
title_img = self.openImage('feature_titles/forecast.png')
@ -2240,13 +2300,12 @@ class StockTicker():
imgs = []
daily_weathers = json.load(open('csv/daily_weather.json', 'r'))
f = open('csv/daily_weather.json', 'r')
daily_weathers = json.load(f)
f.close()
locations = list(daily_weathers['locations'].keys())
for i, location in enumerate(locations):
print(location)
try:
img = Image.new('RGB', (1000, 32))
@ -2271,25 +2330,18 @@ class StockTicker():
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
temp = daily_weather[0]['temp']
min_temp = daily_weather[0]['min_temp']
max_temp = daily_weather[0]['max_temp']
temp = self.convertTemp(daily_weather[0]['temp'], daily_weathers['temp'])
min_temp = self.convertTemp(daily_weather[0]['min_temp'], daily_weathers['temp'])
max_temp = self.convertTemp(daily_weather[0]['max_temp'], daily_weathers['temp'])
if daily_weathers['temp'] == 'kelvin':
temp = daily_weather[0]['temp'] + 273.15
min_temp = daily_weather[0]['min_temp'] + 273.15
max_temp = daily_weather[0]['max_temp'] + 273.15
elif daily_weathers['temp'] == 'fahrenheit':
temp = daily_weather[0]['temp']*9/5 + 32
min_temp = daily_weather[0]['min_temp']*9/5 + 32
max_temp = daily_weather[0]['max_temp']*9/5 + 32
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
deg_img = self.textImage('o', small_font)
min_img = self.textImage( "{0:.0f}".format(min_temp), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(max_temp), small_font, r=255, g=0, b=0)
min_img = self.textImage( "{0:.0f}".format(min_temp, daily_weathers['temp']), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(max_temp, daily_weathers['temp']), small_font, r=255, g=0, b=0)
main = daily_weather[0]['main_weather']
main_img = self.textImage(main.upper(), small_font)
@ -2390,7 +2442,7 @@ class StockTicker():
#img.paste(wind_img, (96,0))
#img.paste(wtext_img, (109,0))
#img.paste(date_img, (70, 0))
x_offset = 70
x_offset = 77
for i in range(1,len(daily_weather)-1):
weekday = weekdays[(datetime.today().weekday() + i)%7]
@ -2405,17 +2457,10 @@ class StockTicker():
min_temp = weather['min_temp']
max_temp = weather['max_temp']
min_temp = self.convertTemp(weather['min_temp'], daily_weathers['temp'])
max_temp = self.convertTemp(weather['max_temp'], daily_weathers['temp'])
if daily_weathers['temp'] == 'kelvin':
min_temp = weather['min_temp'] + 273.15
max_temp = weather['max_temp'] + 273.15
elif daily_weathers['temp'] == 'fahrenheit':
min_temp = weather['min_temp']*9/5 + 32
max_temp = weather['max_temp']*9/5 + 32
weather_img = Image.open(weather_dir + '/small_icons/' + weather_ids[main] + '.png')
min_img = self.textImage( "{0:.0f}".format(min_temp), small_font, r=0, g=0, b=255)
@ -2435,16 +2480,15 @@ class StockTicker():
imgs.append(self.blank)
# add the image text
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
return self.stitchImage(imgs)
@ -2467,8 +2511,6 @@ class StockTicker():
def displayDailyWeatherAlt(self):
img0, img1 = self.getDailyWeatherImageAlt()
#img = stock_ticker.getTodayWeatherImage()
while True:
@ -2483,14 +2525,10 @@ class StockTicker():
while offset_x > 64-img_width:
offset_x -= 1
self.setImage(image, offset_x = offset_x, offset_y = offset_y, min_x = 64, min_y = 9)
if offset_x + img_width < self.matrix.width: # if the image is ending
self.setImage(image, offset_x = offset_x + img_width, offset_y = offset_y, min_x = 64, min_y = 9)
try:
msg = getInput()
if msg == 'K':
@ -2509,8 +2547,6 @@ class StockTicker():
def getUserImages(self):
f = open('csv/image_settings.json', 'r')
all_settings = json.load(f)
f.close()
@ -2520,9 +2556,9 @@ class StockTicker():
try:
img = self.openImage(os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'user_uploads'), image))
print(img)
img.thumbnail((99999, 32))
print(img)
if all_settings['title'] and ind == 0:
title_img = self.openImage('feature_titles/images.png')
imgs.append(self.stitchImage([title_img, img]))
@ -2531,16 +2567,15 @@ class StockTicker():
imgs.append(img)
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
return imgs
@ -2586,15 +2621,15 @@ class StockTicker():
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]
self.logf.write(str(e))
self.logf.write('. file: ' + fname)
self.logf.write('. line: ' + str(exc_tb.tb_lineno))
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()
#below code stitches title and GIF together
@ -2712,11 +2747,15 @@ class StockTicker():
#userSettings = [ 'daily_weather']
#userSettings = ['crypto', 'stocks'] # these wil be read from csv, just for demo
#userSettings = [ 'display_image', 'news'] # these wil be read from csv, just for demo
userSettings = json.load(open('csv/display_settings.json'))
if 'Professional'==userSettings[0] and len(userSettings[1][0])>0 and len(userSettings[1][1])>0: #if professional display
self.scrollProfessionalAnimated(userSettings[1])
elif len(userSettings[1][0])>0 and 'Standard'==userSettings[0]:
self.scrollFunctionsAnimated(userSettings[1][0], animation = 'down')
f = open('csv/display_settings.json', 'r')
user_settings = json.load(f)
f.close()
if 'Professional'==user_settings[0] and len(user_settings[1][0])>0 and len(user_settings[1][1])>0: #if professional display
self.scrollProfessionalAnimated(user_settings[1])
elif len(user_settings[1][0])>0 and 'Standard'==user_settings[0]:
self.scrollFunctionsAnimated(user_settings[1][0], animation = 'down')
elif msg == 'b':
userSettings = json.load(open('csv/display_settings.json'))
@ -2752,24 +2791,8 @@ class StockTicker():
if __name__ == '__main__':
with open('log.txt', "a") as log:
try:
stock_ticker = StockTicker()
stock_ticker.logf = log
#stock_ticker.getLeagueImage('NHL', 'future')
#stock_ticker.getCryptoImage()
#
#stock_ticker.process_msg('*')
#time.sleep(8)
#stock_ticker.process_msg('-')
#stock_ticker.process_msg('W')
#stock_ticker.process_msg('A')
@ -2777,15 +2800,17 @@ if __name__ == '__main__':
msg = getInput()
stock_ticker.process_msg(msg)
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]
log.write(str(e))
log.write('. file: ' + fname)
log.write('. line: ' + str(exc_tb.tb_lineno))
log.write('. type: ' + str(exc_type))
log.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
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])))
logf.close()

View File

@ -88,7 +88,7 @@
<a class="navbar-brand" href="#">
<img src="{{ url_for('static', filename='images/logo_white.png') }}" class="logo" alt="logo" /><p class="text-white">Version 1.0</p>
<img src="{{ url_for('static', filename='images/logo_white.png') }}" class="logo" alt="logo" /><p class="text-white">Version 1.0.1</p>
</a>