startup logo added and dynamic weather layout
This commit is contained in:
parent
271da76900
commit
77fb96e4dc
BIN
logos/startup_logo_1.gif
Normal file
BIN
logos/startup_logo_1.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
@ -44,6 +44,7 @@ ALLOWED_EXTENSIONS = {'csv', 'png'}
|
||||
|
||||
ticker = pexpect.spawn("sudo -E python3 stockTicker.py")
|
||||
ticker.sendline('*') # run by default
|
||||
time.sleep(1)
|
||||
ticker.sendline('A') # run by default
|
||||
|
||||
def allowed_file(filename):
|
||||
|
127
stockTicker.py
127
stockTicker.py
@ -728,19 +728,19 @@ class StockTicker():
|
||||
|
||||
return imgs
|
||||
|
||||
def displayGIF(self, gif):
|
||||
def displayGIF(self, gif, delay = 0.5, repeat = True):
|
||||
# To iterate through the entire gif
|
||||
i = 0
|
||||
while True:
|
||||
try:
|
||||
gif.seek(i)
|
||||
except EOFError:
|
||||
|
||||
if not repeat: break
|
||||
i = 0
|
||||
gif.seek(i)
|
||||
# do something to im
|
||||
self.setImage(gif.convert('RGB'))
|
||||
time.sleep(0.5)
|
||||
time.sleep(delay)
|
||||
i += 1
|
||||
try:
|
||||
msg = getInput()
|
||||
@ -1804,17 +1804,12 @@ class StockTicker():
|
||||
|
||||
for i, location in enumerate(locations):
|
||||
try:
|
||||
img = Image.new('RGB', (208, 32))
|
||||
|
||||
|
||||
current_weather = current_weathers[location]
|
||||
small_font = ImageFont.load("./fonts/5x7.pil")
|
||||
large_font = ImageFont.load("./fonts/10x20.pil")
|
||||
|
||||
location_img = self.textImage(location.upper(), small_font, r = 255, g = 255, b = 0)
|
||||
|
||||
img.paste(location_img, (5,0))
|
||||
|
||||
main = current_weather['main_weather']
|
||||
if main == 'Clouds':
|
||||
main = current_weather['description']
|
||||
@ -1823,12 +1818,7 @@ class StockTicker():
|
||||
'Sand': '50', 'Ash': '50', 'Squall': '50', 'Tornado': '50'}
|
||||
|
||||
weather_dir = './logos/weather_icons'
|
||||
|
||||
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
|
||||
img.paste(weather_img, (5,9))
|
||||
|
||||
|
||||
|
||||
temp = current_weather['temp']
|
||||
feels_temp = current_weather['feels_like']
|
||||
if all_settings['temp'] == 'kelvin':
|
||||
@ -1838,82 +1828,88 @@ class StockTicker():
|
||||
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)
|
||||
|
||||
img.paste(deg_img, (59, 8))
|
||||
|
||||
main = current_weather['main_weather']
|
||||
main_img = self.textImage(main.upper(), small_font)
|
||||
img.paste(main_img, (35, 26))
|
||||
|
||||
|
||||
feels_img = self.textImage('Feels like:'.upper() + str("{0:.0f}".format(feels_temp)), small_font)
|
||||
img.paste(feels_img, (location_img.size[0] + 10, 0))
|
||||
|
||||
min_img = self.textImage( "{0:.0f}".format(current_weather['min_temp']), small_font, r=0, g=0, b=255)
|
||||
img.paste(min_img, (66, 12))
|
||||
|
||||
max_img = self.textImage( "{0:.0f}".format(current_weather['max_temp']), small_font, r=255, g=0, b=0)
|
||||
img.paste(max_img, (66, 21))
|
||||
|
||||
hum_img = Image.open(weather_dir + '/humidity.png')
|
||||
img.paste(hum_img, ( 82, 8))
|
||||
|
||||
htext_img = self.textImage(str(current_weather['humidity']) + '%', small_font)
|
||||
img.paste(htext_img, (95, 10))
|
||||
|
||||
uv_img = Image.open(weather_dir + '/uv.png')
|
||||
img.paste(uv_img, ( 82, 22))
|
||||
|
||||
utext_img = self.textImage(str(round(current_weather['uv'], 1)) , small_font)
|
||||
img.paste(utext_img, (95, 23))
|
||||
|
||||
weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
||||
months =['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
month = months[int(datetime.now().strftime('%m'))-1]
|
||||
date = str(int(datetime.now().strftime('%d')))
|
||||
|
||||
weekday = weekdays[datetime.today().weekday()]
|
||||
|
||||
date_img = self.textImage((month + ' ' + date + ',' + weekday).upper(), small_font)
|
||||
img.paste(date_img, (132, 0))
|
||||
|
||||
rain_img = Image.open(weather_dir + '/rain-chance.png')
|
||||
img.paste(rain_img, (118,8))
|
||||
|
||||
|
||||
rtext_img = self.textImage(str(int(current_weather['rain_chance']*100)) + '%', small_font)
|
||||
img.paste(rtext_img, (131, 10))
|
||||
|
||||
cloud_img = Image.open(weather_dir + '/clouds.png')
|
||||
img.paste(cloud_img, (118,20))
|
||||
|
||||
ctext_img = self.textImage(str(current_weather['clouds']) + '%', small_font)
|
||||
img.paste(ctext_img, (131, 22))
|
||||
|
||||
wind_img = Image.open(weather_dir + '/wind.png')
|
||||
img.paste(wind_img, (154,8))
|
||||
|
||||
|
||||
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, (195, 10))
|
||||
|
||||
vis_img = Image.open(weather_dir + '/visibility.png')
|
||||
img.paste(vis_img, (154,20))
|
||||
|
||||
vtext_img = self.textImage(str(round(current_weather['visibility']/1000, 1)) + 'km'.upper(), small_font)
|
||||
img.paste(vtext_img, (168, 22))
|
||||
|
||||
|
||||
|
||||
'------------------------------------------'
|
||||
img = Image.new('RGB', (1000, 32))
|
||||
|
||||
img.paste(weather_img, (5,9))
|
||||
x_offset = 5 + weather_img.size[0] + 1
|
||||
|
||||
img.paste(main_img, (x_offset, 26))
|
||||
img.paste(temp_img, (x_offset + main_img.size[0]//2 - temp_img.size[0]//2,9))
|
||||
|
||||
img.paste(deg_img, (x_offset + main_img.size[0]//2 - temp_img.size[0]//2 + temp_img.size[0], 8))
|
||||
|
||||
x_offset += max( main_img.size[0], temp_img.size[0] + deg_img.size[0])
|
||||
|
||||
|
||||
img.paste(min_img, (x_offset - 1, 12))
|
||||
img.paste(max_img, (x_offset - 1, 21))
|
||||
|
||||
x_offset += max(min_img.size[0], max_img.size[0]) + 2
|
||||
img.paste(hum_img, ( x_offset, 8))
|
||||
img.paste(uv_img, ( x_offset, 22))
|
||||
|
||||
img.paste(htext_img, (x_offset + hum_img.size[0], 10))
|
||||
img.paste(utext_img, (x_offset + uv_img.size[0], 23))
|
||||
x_offset += max(hum_img.size[0], uv_img.size[0]+2)
|
||||
x_offset += max(htext_img.size[0], utext_img.size[0]) + 6
|
||||
|
||||
|
||||
img.paste(rain_img, (x_offset,8))
|
||||
img.paste(cloud_img, (x_offset,20))
|
||||
img.paste(ctext_img, (x_offset + cloud_img.size[0] + 2, 22))
|
||||
img.paste(rtext_img, (x_offset + rain_img.size[0]+ 2, 10))
|
||||
x_offset += max(cloud_img.size[0], rain_img.size[0])+6
|
||||
x_offset += max(ctext_img.size[0], rtext_img.size[0])+6
|
||||
img.paste(wind_img, (x_offset,8))
|
||||
img.paste(vis_img, (x_offset,20))
|
||||
img.paste(wtext_img, (x_offset + wind_img.size[0] + 2, 10))
|
||||
img.paste(vtext_img, (x_offset + vis_img.size[0] + 2, 22))
|
||||
x_offset += wind_img.size[0] + wtext_img.size[0] + 4
|
||||
img.paste(wdir_img, (x_offset, 10))
|
||||
|
||||
|
||||
|
||||
img = img.crop((0,0,x_offset +wdir_img.size[0] + 4 ,32))
|
||||
|
||||
img.paste(location_img, (5,0))
|
||||
img.paste(feels_img, (location_img.size[0] + 10, 0))
|
||||
img.paste(date_img, (location_img.size[0] + feels_img.size[0] + 15, 0))
|
||||
|
||||
|
||||
|
||||
imgs.append(img)
|
||||
imgs.append(self.blank)
|
||||
@ -1925,7 +1921,7 @@ class StockTicker():
|
||||
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])))
|
||||
|
||||
raise e
|
||||
|
||||
return self.stitchImage(imgs)
|
||||
|
||||
@ -2705,11 +2701,16 @@ if __name__ == '__main__':
|
||||
stock_ticker.logf = log
|
||||
|
||||
start_image = Image.open('./logos/startup_logo.png')
|
||||
start_GIF = Image.open('./logos/startup_logo_1.gif')
|
||||
|
||||
msg = getInput()
|
||||
if msg =='*':
|
||||
stock_ticker.setImage(start_image)
|
||||
time.sleep(1)
|
||||
#
|
||||
#
|
||||
|
||||
stock_ticker.displayGIF(start_GIF, delay = 0.02, repeat = False)
|
||||
#stock_ticker.setImage(start_image)
|
||||
time.sleep(2)
|
||||
stock_ticker.resetMatrix()
|
||||
|
||||
#stock_ticker.getLeagueImage('NHL', 'future')
|
||||
@ -2720,7 +2721,7 @@ if __name__ == '__main__':
|
||||
#stock_ticker.process_msg('G')
|
||||
#stock_ticker.process_msg('f')
|
||||
#stock_ticker.process_msg('W')
|
||||
#stock_ticker.process_msg('A')
|
||||
stock_ticker.process_msg('A')
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user