bug fixes and slight layout changes
This commit is contained in:
parent
395a433aba
commit
de3ed3e01b
@ -85,14 +85,16 @@ 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:
|
||||
|
||||
|
||||
try:
|
||||
method = 'GET'
|
||||
host = 'https://cloud.iexapis.com/stable'
|
||||
|
||||
@ -114,9 +116,17 @@ def updateStocks():
|
||||
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,9 +404,16 @@ 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
|
||||
@ -609,9 +627,17 @@ 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)
|
||||
|
||||
|
128
log.txt
128
log.txt
@ -0,0 +1,128 @@
|
||||
|
||||
list indices must be integers or slices, not str. file: stockTicker.py. line: 2200. type: <class 'TypeError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2200, in getDailyWeatherImage
|
||||
main = daily_weather['description']
|
||||
TypeError: list indices must be integers or slices, not str
|
||||
list indices must be integers or slices, not str. file: stockTicker.py. line: 2200. type: <class 'TypeError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2200, in getDailyWeatherImage
|
||||
main = daily_weather['description']
|
||||
TypeError: list indices must be integers or slices, not str
|
||||
list indices must be integers or slices, not str. file: stockTicker.py. line: 2200. type: <class 'TypeError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2200, in getDailyWeatherImage
|
||||
main = daily_weather['description']
|
||||
TypeError: list indices must be integers or slices, not str
|
||||
list indices must be integers or slices, not str. file: stockTicker.py. line: 2200. type: <class 'TypeError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2200, in getDailyWeatherImage
|
||||
main = daily_weather['description']
|
||||
TypeError: list indices must be integers or slices, not str
|
||||
HTTPConnectionPool(host='api.geonames.org', port=80): Max retries exceeded with url: /searchJSON?q=London&username=fintic&maxRows=1 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xb5c72ed0>, 'Connection to api.geonames.org timed out. (connect timeout=1)')). file: api_caller.py. line: 356. type: <class 'geopy.exc.GeocoderUnavailable'>
|
||||
Traceback (most recent call last):
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
|
||||
(self._dns_host, self.port), self.timeout, **extra_kw)
|
||||
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 80, in create_connection
|
||||
raise err
|
||||
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 70, in create_connection
|
||||
sock.connect(sa)
|
||||
socket.timeout: timed out
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
|
||||
chunked=chunked)
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
|
||||
conn.request(method, url, **httplib_request_kw)
|
||||
File "/usr/lib/python3.7/http/client.py", line 1260, in request
|
||||
self._send_request(method, url, body, headers, encode_chunked)
|
||||
File "/usr/lib/python3.7/http/client.py", line 1306, in _send_request
|
||||
self.endheaders(body, encode_chunked=encode_chunked)
|
||||
File "/usr/lib/python3.7/http/client.py", line 1255, in endheaders
|
||||
self._send_output(message_body, encode_chunked=encode_chunked)
|
||||
File "/usr/lib/python3.7/http/client.py", line 1030, in _send_output
|
||||
self.send(msg)
|
||||
File "/usr/lib/python3.7/http/client.py", line 970, in send
|
||||
self.connect()
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 181, in connect
|
||||
conn = self._new_conn()
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 164, in _new_conn
|
||||
(self.host, self.timeout))
|
||||
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0xb5c72ed0>, 'Connection to api.geonames.org timed out. (connect timeout=1)')
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
|
||||
timeout=timeout
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 667, in urlopen
|
||||
**response_kw)
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 667, in urlopen
|
||||
**response_kw)
|
||||
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
|
||||
_stacktrace=sys.exc_info()[2])
|
||||
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
|
||||
raise MaxRetryError(_pool, url, error or ResponseError(cause))
|
||||
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='api.geonames.org', port=80): Max retries exceeded with url: /searchJSON?q=London&username=fintic&maxRows=1 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xb5c72ed0>, 'Connection to api.geonames.org timed out. (connect timeout=1)'))
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/geopy/adapters.py", line 448, in _request
|
||||
resp = self.session.get(url, timeout=timeout, headers=headers)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/requests/sessions.py", line 555, in get
|
||||
return self.request('GET', url, **kwargs)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
|
||||
resp = self.send(prep, **send_kwargs)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
|
||||
r = adapter.send(request, **kwargs)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/requests/adapters.py", line 504, in send
|
||||
raise ConnectTimeout(e, request=request)
|
||||
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='api.geonames.org', port=80): Max retries exceeded with url: /searchJSON?q=London&username=fintic&maxRows=1 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xb5c72ed0>, 'Connection to api.geonames.org timed out. (connect timeout=1)'))
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "api_caller.py", line 356, in updateWeather
|
||||
loc = gn.geocode(location)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/geopy/geocoders/geonames.py", line 157, in geocode
|
||||
return self._call_geocoder(url, callback, timeout=timeout)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/geopy/geocoders/base.py", line 368, in _call_geocoder
|
||||
result = self.adapter.get_json(url, timeout=timeout, headers=req_headers)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/geopy/adapters.py", line 438, in get_json
|
||||
resp = self._request(url, timeout=timeout, headers=headers)
|
||||
File "/home/pi/.local/lib/python3.7/site-packages/geopy/adapters.py", line 460, in _request
|
||||
raise GeocoderUnavailable(message)
|
||||
geopy.exc.GeocoderUnavailable: HTTPConnectionPool(host='api.geonames.org', port=80): Max retries exceeded with url: /searchJSON?q=London&username=fintic&maxRows=1 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xb5c72ed0>, 'Connection to api.geonames.org timed out. (connect timeout=1)'))
|
||||
local variable 'temp' referenced before assignment. file: stockTicker.py. line: 2239. type: <class 'UnboundLocalError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2239, in getDailyWeatherImage
|
||||
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
|
||||
UnboundLocalError: local variable 'temp' referenced before assignment
|
||||
local variable 'temp' referenced before assignment. file: stockTicker.py. line: 2239. type: <class 'UnboundLocalError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2239, in getDailyWeatherImage
|
||||
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
|
||||
UnboundLocalError: local variable 'temp' referenced before assignment
|
||||
local variable 'temp' referenced before assignment. file: stockTicker.py. line: 2239. type: <class 'UnboundLocalError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2239, in getDailyWeatherImage
|
||||
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
|
||||
UnboundLocalError: local variable 'temp' referenced before assignment
|
||||
local variable 'temp' referenced before assignment. file: stockTicker.py. line: 2239. type: <class 'UnboundLocalError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2239, in getDailyWeatherImage
|
||||
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
|
||||
UnboundLocalError: local variable 'temp' referenced before assignment
|
||||
local variable 'temp' referenced before assignment. file: stockTicker.py. line: 2239. type: <class 'UnboundLocalError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2239, in getDailyWeatherImage
|
||||
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
|
||||
UnboundLocalError: local variable 'temp' referenced before assignment
|
||||
local variable 'temp' referenced before assignment. file: stockTicker.py. line: 2239. type: <class 'UnboundLocalError'>
|
||||
Traceback (most recent call last):
|
||||
File "stockTicker.py", line 2239, in getDailyWeatherImage
|
||||
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
|
||||
UnboundLocalError: local variable 'temp' referenced before assignment
|
11
server.py
11
server.py
@ -22,6 +22,7 @@ import copy
|
||||
#stock_ticker = StockTicker()
|
||||
#print('API CALLER NOT STARTED')
|
||||
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
|
||||
api_caller.sendline('A')
|
||||
displaying_screensaver = False
|
||||
screensaver_p = None
|
||||
professional = json.load(open('csv/display_settings.json', 'r'))[0] == "Professional"
|
||||
@ -44,7 +45,7 @@ def allowed_file(filename):
|
||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||
|
||||
def process_file(path, filename):
|
||||
default_csv = csv.writer(open('csv/tickers.csv', 'w'))
|
||||
default_csv = csv.writer(open('csv/tickers.csv', 'w+'))
|
||||
new_csv = csv.reader(open((path), 'r'))
|
||||
|
||||
for row in new_csv:
|
||||
@ -187,6 +188,7 @@ def stop():
|
||||
@app.route("/update", methods=['PUT','POST'])
|
||||
def update():
|
||||
os.system("./update.sh")
|
||||
os.system("sudo reboot now")
|
||||
return index()
|
||||
|
||||
@app.route("/display_format", methods = ['PUT', 'POST', 'GET'])
|
||||
@ -393,10 +395,6 @@ def combine_dict(current_settings, input_symbols, current_key):
|
||||
else:
|
||||
new_settings[current_key][IS] = current_settings[current_key][IS]
|
||||
|
||||
# remove stocks not in settings
|
||||
for CS in current_symbols:
|
||||
if CS not in input_symbols:
|
||||
del new_settings[current_key][CS]
|
||||
|
||||
return new_settings
|
||||
|
||||
@ -448,11 +446,14 @@ def save_weather_settings(input_settings):
|
||||
if input_settings['feature'] == 'Daily Forecast':
|
||||
current_settings['current_weather'] = input_settings['current_weather']
|
||||
|
||||
'''
|
||||
locations = {}
|
||||
for key in input_settings['locations']:
|
||||
locations[key] = []
|
||||
current_settings['locations'] = locations
|
||||
'''
|
||||
|
||||
current_settings = combine_dict(current_settings, input_settings['locations'], 'locations')
|
||||
json.dump(current_settings, open('csv/' + filename, 'w+'))
|
||||
|
||||
api_caller.sendline('w')
|
||||
|
248
stockTicker.py
248
stockTicker.py
@ -830,13 +830,13 @@ class StockTicker():
|
||||
|
||||
|
||||
if point_change:
|
||||
d.text(((text_width_current+29), 16), point_change, fill=self.greenORred, font=font)
|
||||
d.text(((w1+29), 16), point_change, fill=self.greenORred, font=font)
|
||||
|
||||
if percent_change:
|
||||
d.text(((text_width_current+29), 14 - text_height), percent_change, fill=self.greenORred, font=font)
|
||||
d.text(((w2+7), 14 - text_height), percent_change, fill=self.greenORred, font=font)
|
||||
|
||||
if point_change or percent_change:
|
||||
img.paste(ARROW, ((text_width_current + 9),18))
|
||||
img.paste(ARROW, ((w1+ 9),18))
|
||||
|
||||
|
||||
text_width_change=0
|
||||
@ -913,6 +913,7 @@ class StockTicker():
|
||||
coin_bases = list(coin_info.keys())
|
||||
|
||||
for i, cb in enumerate(coin_bases):
|
||||
try:
|
||||
ticker, base = cb.split(',')
|
||||
current = float(coin_info[cb]["current"])
|
||||
change = float(coin_info[cb]["24hr_change"])
|
||||
@ -938,7 +939,7 @@ class StockTicker():
|
||||
try:
|
||||
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'crypto')
|
||||
|
||||
logo = Image.open(os.path.join(logos_path, ticker + '.png'))
|
||||
logo = self.openImage(os.path.join(logos_path, ticker + '.png'))
|
||||
stitchedStock = self.stitchImage([logo,midFrame])
|
||||
except:
|
||||
|
||||
@ -950,6 +951,16 @@ class StockTicker():
|
||||
|
||||
image_list.append(self.blank)
|
||||
|
||||
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]
|
||||
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])))
|
||||
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
|
||||
return finalDisplayImage
|
||||
@ -979,7 +990,7 @@ class StockTicker():
|
||||
|
||||
|
||||
for i, cb in enumerate(coin_bases):
|
||||
|
||||
try:
|
||||
ticker, base = cb.split(',')
|
||||
current = coin_info[cb]["current"]
|
||||
change = coin_info[cb]["24hr_change"]
|
||||
@ -998,7 +1009,7 @@ class StockTicker():
|
||||
if all_crypto_settings['logos']:
|
||||
try:
|
||||
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'crypto')
|
||||
logo = Image.open(os.path.join(logos_path, ticker + '.png'))
|
||||
logo = self.openImage(os.path.join(logos_path, ticker + '.png'))
|
||||
|
||||
w,h = logo.size
|
||||
logo=logo.resize((int(w/2), int(h/2)))
|
||||
@ -1012,6 +1023,15 @@ class StockTicker():
|
||||
|
||||
image_list.append(self.blank)
|
||||
|
||||
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]
|
||||
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])))
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
self.blank = Image.new('RGB', (10, 32))
|
||||
return finalDisplayImage
|
||||
@ -1035,6 +1055,7 @@ class StockTicker():
|
||||
symbol_bases = list(forex_settings.keys())
|
||||
|
||||
for i, sb in enumerate(symbol_bases):
|
||||
try:
|
||||
symbol, base = sb.split(',')
|
||||
|
||||
current = float(forex_settings[sb]['current'])
|
||||
@ -1081,6 +1102,17 @@ class StockTicker():
|
||||
|
||||
image_list.append(midFrame)
|
||||
image_list.append(self.blank)
|
||||
|
||||
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]
|
||||
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])))
|
||||
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
|
||||
return finalDisplayImage
|
||||
@ -1106,6 +1138,7 @@ class StockTicker():
|
||||
|
||||
|
||||
for i, sb in enumerate(symbol_bases):
|
||||
try:
|
||||
symbol, base = sb.split(',')
|
||||
|
||||
current = forex_settings[sb]['current']
|
||||
@ -1153,14 +1186,22 @@ class StockTicker():
|
||||
|
||||
image_list.append(self.blank)
|
||||
|
||||
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]
|
||||
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])))
|
||||
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
self.blank = Image.new('RGB', (10, 32))
|
||||
return finalDisplayImage
|
||||
|
||||
def getStockImage(self):
|
||||
|
||||
|
||||
|
||||
f = open('csv/stocks_settings.json', 'r')
|
||||
all_stocks_settings = json.load(f)
|
||||
f.close()
|
||||
@ -1180,7 +1221,7 @@ class StockTicker():
|
||||
|
||||
for i, symbol in enumerate(symbols):
|
||||
|
||||
|
||||
try:
|
||||
info = stock_info[symbol]
|
||||
|
||||
change = float(info['current'])-float(info['opening']) #TEXT
|
||||
@ -1210,10 +1251,10 @@ class StockTicker():
|
||||
try:
|
||||
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks')
|
||||
|
||||
logo = Image.open(os.path.join(logos_path, ticker + '.png'))
|
||||
logo = self.openImage(os.path.join(logos_path, ticker + '.png'))
|
||||
stitchedStock = self.stitchImage([logo,midFrame])
|
||||
except:
|
||||
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
stitchedStock = midFrame
|
||||
else:
|
||||
stitchedStock = midFrame
|
||||
@ -1222,6 +1263,15 @@ class StockTicker():
|
||||
|
||||
|
||||
image_list.append(self.blank)
|
||||
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]
|
||||
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])))
|
||||
|
||||
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
@ -1250,7 +1300,7 @@ class StockTicker():
|
||||
|
||||
for i, symbol in enumerate(symbols):
|
||||
|
||||
|
||||
try:
|
||||
info = stock_info[symbol]
|
||||
|
||||
change = float(info['current'])-float(info['opening']) #TEXT
|
||||
@ -1298,6 +1348,15 @@ class StockTicker():
|
||||
|
||||
image_list.append(self.blank)
|
||||
|
||||
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]
|
||||
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])))
|
||||
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
|
||||
@ -1325,6 +1384,7 @@ class StockTicker():
|
||||
|
||||
|
||||
for i, hi in enumerate(headline_info):
|
||||
try:
|
||||
headline, source, date_time = hi
|
||||
date, time = date_time.split('T')
|
||||
time = time[:-1]
|
||||
@ -1368,6 +1428,14 @@ class StockTicker():
|
||||
|
||||
image_list.append(img)
|
||||
image_list.append(self.blank)
|
||||
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]
|
||||
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])))
|
||||
|
||||
news_image = self.stitchImage(image_list)
|
||||
|
||||
@ -1394,6 +1462,7 @@ class StockTicker():
|
||||
blank = Image.new('RGB', (0, 16))
|
||||
|
||||
for i, hi in enumerate(headline_info):
|
||||
try:
|
||||
headline, source, date_time = hi
|
||||
date, time = date_time.split('T')
|
||||
time = time[:-1]
|
||||
@ -1443,6 +1512,14 @@ class StockTicker():
|
||||
|
||||
image_list.append(img)
|
||||
image_list.append(blank)
|
||||
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]
|
||||
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])))
|
||||
news_image = self.stitchImage(image_list)
|
||||
|
||||
return news_image
|
||||
@ -1471,6 +1548,7 @@ class StockTicker():
|
||||
|
||||
|
||||
for league in leagues:
|
||||
try:
|
||||
|
||||
|
||||
x_offset = 0
|
||||
@ -1598,6 +1676,14 @@ class StockTicker():
|
||||
x_offset += buff_size
|
||||
img = img.crop((0,0,x_offset ,32))
|
||||
imgs.append(img)
|
||||
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]
|
||||
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])))
|
||||
|
||||
|
||||
|
||||
@ -1620,7 +1706,7 @@ class StockTicker():
|
||||
imgs = []
|
||||
|
||||
for league in leagues:
|
||||
|
||||
try:
|
||||
x_offset = 0
|
||||
|
||||
img = Image.new('RGB', (10000, 32))
|
||||
@ -1680,6 +1766,14 @@ class StockTicker():
|
||||
|
||||
img = img.crop((0,0,x_offset ,32))
|
||||
imgs.append(img)
|
||||
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]
|
||||
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])))
|
||||
|
||||
return self.stitchImage(imgs)
|
||||
|
||||
@ -1698,6 +1792,7 @@ class StockTicker():
|
||||
locations = list(current_weathers.keys())
|
||||
|
||||
for i, location in enumerate(locations):
|
||||
try:
|
||||
img = Image.new('RGB', (203, 32))
|
||||
|
||||
|
||||
@ -1721,7 +1816,15 @@ class StockTicker():
|
||||
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
|
||||
img.paste(weather_img, (5,9))
|
||||
|
||||
temp_img = self.textImage(str("{0:.0f}".format(current_weather['temp'])), large_font)
|
||||
|
||||
|
||||
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_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
|
||||
img.paste(temp_img, (39,9))
|
||||
|
||||
deg_img = self.textImage('o', small_font)
|
||||
@ -1779,11 +1882,18 @@ class StockTicker():
|
||||
wind_img = Image.open(weather_dir + '/wind.png')
|
||||
img.paste(wind_img, (154,8))
|
||||
|
||||
wtext_img = self.textImage("{0:.0f}".format(current_weather['wind_speed']) + 'm/s'.upper(), small_font)
|
||||
|
||||
w_speed = current_weather['wind_speed']*3.6
|
||||
w_unit = 'K/H'
|
||||
if all_settings["wind_speed"] == "miles/hour":
|
||||
w_speed = current_weather['wind_speed']*2.236936
|
||||
w_unit = 'M/H'
|
||||
|
||||
wtext_img = self.textImage("{0:.0f}".format(w_speed) + w_unit, small_font)
|
||||
img.paste(wtext_img, (168, 10))
|
||||
|
||||
wdir_img = self.textImage(self.degreesToCompass(current_weather['wind_direction']).upper(), small_font)
|
||||
img.paste(wdir_img, (191, 10))
|
||||
img.paste(wdir_img, (195, 10))
|
||||
|
||||
vis_img = Image.open(weather_dir + '/visibility.png')
|
||||
img.paste(vis_img, (154,20))
|
||||
@ -1793,6 +1903,14 @@ class StockTicker():
|
||||
|
||||
imgs.append(img)
|
||||
imgs.append(self.blank)
|
||||
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]
|
||||
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])))
|
||||
|
||||
|
||||
return self.stitchImage(imgs)
|
||||
@ -1819,6 +1937,7 @@ class StockTicker():
|
||||
weekday = weekdays[datetime.today().weekday()]
|
||||
|
||||
for i, location in enumerate(locations):
|
||||
try:
|
||||
|
||||
img = Image.new('RGB', (1000, 32))
|
||||
|
||||
@ -1863,7 +1982,15 @@ class StockTicker():
|
||||
|
||||
x_offset += weather_img.size[0] + 2
|
||||
|
||||
temp_img = self.textImage(str("{0:.0f}".format(current_weather['temp'])), font)
|
||||
|
||||
|
||||
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_img = self.textImage(str("{0:.0f}".format(temp)), font)
|
||||
img.paste(temp_img, (x_offset,3))
|
||||
x_offset += temp_img.size[0]-3
|
||||
|
||||
@ -1892,7 +2019,15 @@ class StockTicker():
|
||||
cloud_img = Image.open(weather_dir + '/clouds.png')
|
||||
ctext_img = self.textImage(str(current_weather['clouds']) + '%', font)
|
||||
wind_img = Image.open(weather_dir + '/wind.png')
|
||||
wtext_img = self.textImage("{0:.0f}".format(current_weather['wind_speed']) + 'm/s', font)
|
||||
|
||||
w_speed = current_weather['wind_speed']*3.6
|
||||
w_unit = 'K/H'
|
||||
if all_settings["wind_speed"] == "miles/hour":
|
||||
w_speed = current_weather['wind_speed']*2.236936
|
||||
w_unit = 'M/H'
|
||||
|
||||
|
||||
wtext_img = self.textImage("{0:.0f}".format(wind_speed) + wind_unit, font)
|
||||
wdir_img = self.textImage(self.degreesToCompass(current_weather['wind_direction']).upper(), font)
|
||||
vis_img = Image.open(weather_dir + '/visibility.png')
|
||||
vtext_img = self.textImage(str(current_weather['visibility']/1000) + 'km', font)
|
||||
@ -1908,6 +2043,14 @@ class StockTicker():
|
||||
img = img.crop((0,0,x_offset +image.size[0] ,16))
|
||||
|
||||
image_list.append(img)
|
||||
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]
|
||||
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])))
|
||||
return self.stitchImage(image_list)
|
||||
|
||||
def getDailyWeatherImageAlt(self):
|
||||
@ -2070,6 +2213,8 @@ class StockTicker():
|
||||
locations = list(daily_weathers['locations'].keys())
|
||||
|
||||
for i, location in enumerate(locations):
|
||||
print(location)
|
||||
try:
|
||||
img = Image.new('RGB', (1000, 32))
|
||||
|
||||
|
||||
@ -2083,7 +2228,7 @@ class StockTicker():
|
||||
location_img = self.textImage(location.upper(), extra_small_font, r = 255, g = 255, b = 0)
|
||||
main = daily_weather[0]['main_weather']
|
||||
if main == 'Clouds':
|
||||
main = daily_weather['description']
|
||||
main = daily_weather[0]['description']
|
||||
weather_ids = {'Clear': '01', 'few clouds': '02', 'scattered clouds': '03', 'broken clouds':'04', 'overcast clouds':'04', 'Drizzle':'09',
|
||||
'Rain':'10', 'Thunderstorm':'11', 'Snow':'13', 'Mist': '50', 'Smoke': '50', 'Haze': '50', 'Dust': '50', 'Fog': '50',
|
||||
'Sand': '50', 'Ash': '50', 'Squall': '50', 'Tornado': '50'}
|
||||
@ -2091,11 +2236,27 @@ class StockTicker():
|
||||
weather_dir = './logos/weather_icons'
|
||||
|
||||
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
|
||||
temp_img = self.textImage(str("{0:.0f}".format(daily_weather[0]['temp'])), large_font)
|
||||
|
||||
|
||||
temp = daily_weather[0]['temp']
|
||||
min_temp = daily_weather[0]['min_temp']
|
||||
max_temp = daily_weather[0]['max_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(daily_weather[0]['min_temp']), small_font, r=0, g=0, b=255)
|
||||
max_img = self.textImage( "{0:.0f}".format(daily_weather[0]['max_temp']), small_font, r=255, g=0, b=0)
|
||||
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)
|
||||
main = daily_weather[0]['main_weather']
|
||||
main_img = self.textImage(main.upper(), small_font)
|
||||
|
||||
@ -2119,7 +2280,16 @@ class StockTicker():
|
||||
cloud_img = Image.open(weather_dir + '/clouds.png')
|
||||
ctext_img = self.textImage(str(daily_weather[0]['clouds']) + '%', small_font)
|
||||
wind_img = Image.open(weather_dir + '/wind.png')
|
||||
wtext_img = self.textImage("{0:.0f}".format(daily_weather[0]['wind_speed']) + 'm/s'.upper(), small_font)
|
||||
|
||||
|
||||
w_speed = daily_weather[0]['wind_speed']*3.6
|
||||
w_unit = 'K/H'
|
||||
if daily_weathers['wind_speed'] == "miles/hour":
|
||||
w_speed = daily_weather[0]['wind_speed']*2.236936
|
||||
w_unit = 'M/H'
|
||||
|
||||
|
||||
wtext_img = self.textImage("{0:.0f}".format(w_speed) + w_unit, small_font)
|
||||
wdir_img = self.textImage(self.degreesToCompass(daily_weather[0]['wind_direction']), small_font)
|
||||
vis_img = Image.open(weather_dir + '/visibility.png')
|
||||
vtext_img = self.textImage(str(round(daily_weather[0]['visibility']/1000, 1)) + 'km'.upper(), small_font)
|
||||
@ -2186,11 +2356,25 @@ class StockTicker():
|
||||
if main == 'Clouds':
|
||||
main = weather['description']
|
||||
|
||||
|
||||
|
||||
min_temp = weather['min_temp']
|
||||
max_temp = weather['max_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(weather['min_temp']), small_font, r=0, g=0, b=255)
|
||||
min_img = self.textImage( "{0:.0f}".format(min_temp), small_font, r=0, g=0, b=255)
|
||||
|
||||
|
||||
max_img = self.textImage( "{0:.0f}".format(weather['max_temp']), small_font, r=255, g=0, b=0)
|
||||
max_img = self.textImage( "{0:.0f}".format(max_temp), small_font, r=255, g=0, b=0)
|
||||
|
||||
img.paste(day_img, (x_offset +5, 9))
|
||||
img.paste(weather_img, (x_offset +5, 16))
|
||||
@ -2203,6 +2387,15 @@ class StockTicker():
|
||||
imgs.append(img1)
|
||||
imgs.append(self.blank)
|
||||
# add the image text
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
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])))
|
||||
|
||||
|
||||
|
||||
@ -2452,9 +2645,10 @@ class StockTicker():
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
with open('log.txt', "w") as log:
|
||||
with open('log.txt', "a") as log:
|
||||
try:
|
||||
stock_ticker = StockTicker()
|
||||
stock_ticker.logf = log
|
||||
|
||||
start_image = Image.open('./logos/startup_logo.png')
|
||||
|
||||
|
@ -1226,8 +1226,8 @@
|
||||
id="inputTransition42"
|
||||
class="form-select wind-speed-select"
|
||||
>
|
||||
<option>Miles/sec</option>
|
||||
<option>Kilometer/sec</option>
|
||||
<option>Miles/hour</option>
|
||||
<option>Kilometers/hour</option>
|
||||
<option></option>
|
||||
<option></option>
|
||||
<option></option>
|
||||
@ -1447,8 +1447,8 @@
|
||||
id="inputTransition52"
|
||||
class="form-select wind-speed-select"
|
||||
>
|
||||
<option>Miles/sec</option>
|
||||
<option>Kilometer/sec</option>
|
||||
<option>Miles/hour</option>
|
||||
<option>Kilometers/hour</option>
|
||||
<option></option>
|
||||
<option></option>
|
||||
<option></option>
|
||||
|
Loading…
Reference in New Issue
Block a user