past upcoming sports prof
This commit is contained in:
parent
569d5cf106
commit
35829c73d7
162
stockTicker.py
162
stockTicker.py
@ -73,7 +73,8 @@ class StockTicker():
|
|||||||
|
|
||||||
'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional,
|
'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional,
|
||||||
'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional,
|
'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional,
|
||||||
'Daily Forecast Prof':self.getDailyWeatherProfessional, 'Sports (Team Stats) Prof':lambda : self.getLeagueTableProfessional('NHL')}
|
'Daily Forecast Prof':self.getDailyWeatherProfessional, 'Sports (Team Stats) Prof':lambda : self.getLeagueTableProfessional('NHL'), 'Sports (Upcoming Games) Prof': lambda : self.getLeagueProfessional('NHL', 'future'),
|
||||||
|
'Sports (Past Games) Prof': lambda : self.getLeagueProfessional('NBA', 'past')}
|
||||||
|
|
||||||
self.JSONs = {'Stocks': 'csv/stocks_settings.json', 'Crypto': 'csv/crypto_settings.json', 'Forex': 'csv/forex_settings.json',
|
self.JSONs = {'Stocks': 'csv/stocks_settings.json', 'Crypto': 'csv/crypto_settings.json', 'Forex': 'csv/forex_settings.json',
|
||||||
'Daily Forecast':'csv/daily_weather.json', 'Current Weather': 'csv/current_weather.json', 'Commodities':'csv/commodities_settings.json', 'Indices': 'csv/indices_settings.json',
|
'Daily Forecast':'csv/daily_weather.json', 'Current Weather': 'csv/current_weather.json', 'Commodities':'csv/commodities_settings.json', 'Indices': 'csv/indices_settings.json',
|
||||||
@ -82,7 +83,7 @@ class StockTicker():
|
|||||||
'News':'csv/news_settings.json', 'Custom Images': 'csv/image_settings.json', 'Custom GIFs': 'csv/GIF_settings.json', 'Custom Messages': 'csv/message_settings.json',
|
'News':'csv/news_settings.json', 'Custom Images': 'csv/image_settings.json', 'Custom GIFs': 'csv/GIF_settings.json', 'Custom Messages': 'csv/message_settings.json',
|
||||||
'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json',
|
'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json',
|
||||||
'Current Weather Prof': 'csv/current_weather.json', 'News Prof':'csv/news_settings.json', 'Commodities Prof':'csv/commodities_settings.json', 'Indices Prof': 'csv/indices_settings.json',
|
'Current Weather Prof': 'csv/current_weather.json', 'News Prof':'csv/news_settings.json', 'Commodities Prof':'csv/commodities_settings.json', 'Indices Prof': 'csv/indices_settings.json',
|
||||||
'Daily Forecast Prof':'csv/daily_weather.json', 'Sports (Team Stats) Prof': 'csv/league_tables.json'}
|
'Daily Forecast Prof':'csv/daily_weather.json', 'Sports (Team Stats) Prof': 'csv/league_tables.json', 'Sports (Upcoming Games) Prof': 'csv/upcoming_games.json', 'Sports (Past Games) Prof': 'csv/past_games.json'}
|
||||||
|
|
||||||
|
|
||||||
def openImage(self, image_file):
|
def openImage(self, image_file):
|
||||||
@ -2301,6 +2302,157 @@ class StockTicker():
|
|||||||
return self.stitchImage(imgs)
|
return self.stitchImage(imgs)
|
||||||
|
|
||||||
|
|
||||||
|
def getLeagueProfessional(self, league=False, time = 'future'):
|
||||||
|
|
||||||
|
if time in ['past', 'live']:
|
||||||
|
filepath = 'csv/{}_games.json'.format(time)
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
filepath = 'csv/upcoming_games.json'
|
||||||
|
|
||||||
|
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/small_feature_titles/sports_{}.png'.format(time))
|
||||||
|
imgs = [title_img, self.blank]
|
||||||
|
else:
|
||||||
|
imgs = []
|
||||||
|
|
||||||
|
|
||||||
|
leagues_info = all_settings['leagues']
|
||||||
|
leagues = list(leagues_info.keys())
|
||||||
|
|
||||||
|
|
||||||
|
for league in leagues:
|
||||||
|
try:
|
||||||
|
x_offset = 0
|
||||||
|
img = Image.new('RGB', (10000, 32))
|
||||||
|
league_info = leagues_info[league]
|
||||||
|
|
||||||
|
#league logo
|
||||||
|
try:
|
||||||
|
league_logo = Image.open('logos/sports/league_logos/{}.png'.format(league)).convert('RGB')
|
||||||
|
width, height = league_logo.size
|
||||||
|
league_logo2 = league_logo.resize((int(width/2), int(height/2)))
|
||||||
|
img.paste(league_logo2, (x_offset,0))
|
||||||
|
x_offset += (league_logo2.size[0]+10)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
font = ImageFont.load("./fonts/6x10.pil")
|
||||||
|
small_font = ImageFont.load("./fonts/4x6.pil")
|
||||||
|
|
||||||
|
sports_info = self.readSportsCSV(league)
|
||||||
|
|
||||||
|
buff_size = 20
|
||||||
|
|
||||||
|
|
||||||
|
for match in league_info:
|
||||||
|
strHomeTeam = match['home_team']
|
||||||
|
strAwayTeam = match['away_team']
|
||||||
|
|
||||||
|
if time != 'future':
|
||||||
|
intHomeScore = str(match['home_score'])
|
||||||
|
intAwayScore = str(match['away_score'])
|
||||||
|
|
||||||
|
dateEvent = match['date'].replace('-', '.')
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strHomeTeam]['logo']))
|
||||||
|
width1, height1 = home_logo.size
|
||||||
|
home_logo1 = home_logo.resize((int(width1/2), int(height1/2)))
|
||||||
|
except Exception as e:
|
||||||
|
home_logo1 = self.textImage(strHomeTeam.replace(' ', '\n'), font, r = 255, g = 255, b = 255)
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strAwayTeam]['logo']))
|
||||||
|
width2, height2 = away_logo.size
|
||||||
|
away_logo1 = away_logo.resize((int(width2/2), int(height2/2)))
|
||||||
|
except Exception as e:
|
||||||
|
away_logo1 = self.textImage(strAwayTeam.replace(' ', '\n'), font, r = 255, g = 255, b = 255)
|
||||||
|
|
||||||
|
|
||||||
|
date_timage = self.textImage(dateEvent, small_font, r = 255, g = 255, b = 255)
|
||||||
|
|
||||||
|
|
||||||
|
img.paste(home_logo1, (x_offset,0))
|
||||||
|
x_offset += (home_logo1.size[0] + 2)
|
||||||
|
|
||||||
|
|
||||||
|
if time == 'future':
|
||||||
|
img.paste(date_timage, (x_offset+5, 0))
|
||||||
|
|
||||||
|
h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', ''))
|
||||||
|
a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', ''))
|
||||||
|
|
||||||
|
|
||||||
|
hc_timage = self.textImage(sports_info[strHomeTeam]['code'], font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
|
||||||
|
ac_timage = self.textImage(sports_info[strAwayTeam]['code'], font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
|
||||||
|
vs_timage = self.textImage('vs', font, r = 255, g = 255, b = 255, h_buff = 5)
|
||||||
|
|
||||||
|
img.paste(hc_timage, (x_offset, 5))
|
||||||
|
x_offset += hc_timage.size[0]
|
||||||
|
img.paste(vs_timage, (x_offset, 5))
|
||||||
|
x_offset += vs_timage.size[0]
|
||||||
|
img.paste(ac_timage, (x_offset, 5))
|
||||||
|
x_offset += ac_timage.size[0]
|
||||||
|
#x_offset += max(date_timage.size[0], (hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]))
|
||||||
|
else:
|
||||||
|
|
||||||
|
score_image = self.textImage(intHomeScore + '-' + intAwayScore, font, h_buff = 5, r = 255, g = 255, b = 255)
|
||||||
|
h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', ''))
|
||||||
|
a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', ''))
|
||||||
|
|
||||||
|
hc_timage = self.textImage(sports_info[strHomeTeam]['code'], font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
|
||||||
|
ac_timage = self.textImage(sports_info[strAwayTeam]['code'], font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
|
||||||
|
|
||||||
|
img.paste(date_timage, (x_offset+20+int((score_image.size[0] - date_timage.size[0])/2),0))
|
||||||
|
img.paste(hc_timage, (x_offset, 5))
|
||||||
|
x_offset += hc_timage.size[0]
|
||||||
|
img.paste(score_image, (x_offset, 5))
|
||||||
|
x_offset += score_image.size[0]
|
||||||
|
img.paste(ac_timage, (x_offset, 5))
|
||||||
|
x_offset += ac_timage.size[0]
|
||||||
|
|
||||||
|
# if date_timage.size[0] > score_image.size[0]:
|
||||||
|
# img.paste(date_timage, (x_offset+2, 0))
|
||||||
|
# img.paste(hc_timage, (x_offset+6, 5))
|
||||||
|
# img.paste(vs_timage, (x_offset+5 + hc_timage.size[0], 5))
|
||||||
|
# img.paste(ac_timage, (x_offset+6 + hc_timage.size[0] + vs_timage.size[0], 5))
|
||||||
|
# img.paste(score_image, (x_offset + 2 + int((date_timage.size[0] - score_image.size[0])/2), 5))
|
||||||
|
# else:
|
||||||
|
|
||||||
|
# img.paste(date_timage, (x_offset+1+int((score_image.size[0] - date_timage.size[0] )/2), 0))
|
||||||
|
# vs_size = hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]
|
||||||
|
# img.paste(hc_timage, (x_offset + 1 + int((score_image.size[0] - vs_size)/2), 5))
|
||||||
|
# img.paste(vs_timage, (x_offset + int((score_image.size[0] - vs_size)/2) + hc_timage.size[0], 5))
|
||||||
|
# img.paste(ac_timage, (x_offset+1 + int((score_image.size[0] - vs_size)/2) + hc_timage.size[0] + vs_timage.size[0], 5))
|
||||||
|
# img.paste(score_image, (x_offset+1, 5))
|
||||||
|
|
||||||
|
# x_offset += max( date_timage.size[0]+4, hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]+4, 2 + int(score_image.size[0]))
|
||||||
|
|
||||||
|
img.paste(away_logo1, (x_offset,0))
|
||||||
|
|
||||||
|
x_offset += away_logo1.size[0]
|
||||||
|
x_offset += buff_size
|
||||||
|
x_offset += 20
|
||||||
|
img = img.crop((0,0,x_offset ,16))
|
||||||
|
imgs.append(img)
|
||||||
|
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return self.stitchImage(imgs)
|
||||||
|
|
||||||
|
|
||||||
def convertTemp(self,temp, setting):
|
def convertTemp(self,temp, setting):
|
||||||
if setting == 'kelvin':
|
if setting == 'kelvin':
|
||||||
temp = temp+ 273.15
|
temp = temp+ 273.15
|
||||||
@ -3273,6 +3425,8 @@ class StockTicker():
|
|||||||
indices = self.getIndicesProfessional()
|
indices = self.getIndicesProfessional()
|
||||||
daily_forecast = self.getDailyWeatherProfessional()
|
daily_forecast = self.getDailyWeatherProfessional()
|
||||||
sports_stats = self.getLeagueTableProfessional()
|
sports_stats = self.getLeagueTableProfessional()
|
||||||
|
sports_upcoming = self.getLeagueProfessional()
|
||||||
|
sports_past = self.getLeagueProfessional()
|
||||||
|
|
||||||
x_offset = 0
|
x_offset = 0
|
||||||
news.paste(weather, (x_offset, 16))
|
news.paste(weather, (x_offset, 16))
|
||||||
@ -3291,6 +3445,10 @@ class StockTicker():
|
|||||||
x_offset += daily_forecast.size[0]
|
x_offset += daily_forecast.size[0]
|
||||||
news.paste(sports_stats, (x_offset, 16))
|
news.paste(sports_stats, (x_offset, 16))
|
||||||
x_offset += sports_stats.size[0]
|
x_offset += sports_stats.size[0]
|
||||||
|
news.paste(sports_upcoming, (x_offset, 16))
|
||||||
|
x_offset += sports_upcoming.size[0]
|
||||||
|
news.paste(sports_past, (x_offset, 16))
|
||||||
|
x_offset += sports_past.size[0]
|
||||||
self.double_buffer = self.matrix.CreateFrameCanvas()
|
self.double_buffer = self.matrix.CreateFrameCanvas()
|
||||||
while True:
|
while True:
|
||||||
kill = stock_ticker.scrollImage(news, offset_x = 128)
|
kill = stock_ticker.scrollImage(news, offset_x = 128)
|
||||||
|
Loading…
Reference in New Issue
Block a user