lpga and pga world ranking prof

This commit is contained in:
Justin 2023-05-09 17:47:17 +08:00 committed by GitHub
parent ea5fd4afb1
commit a1015a617c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3385,7 +3385,6 @@ class StockTicker():
all_settings = json.load(f)
f.close()
leagues_info = all_settings['leagues']
leagues = list(leagues_info.keys())
@ -3396,49 +3395,152 @@ class StockTicker():
else:
imgs = []
for league in leagues:
try:
x_offset = 0
img = Image.new('RGB', (10000, 32))
if league == 'PGA':
league_logo = Image.open('logos/sports/league_logos/pga_1.png').convert('RGB')
elif league == 'LPGA':
league_logo = Image.open('logos/sports/league_logos/lpga_1.png').convert('RGB')
else:
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]+5)
team_info = leagues_info[league]
font = ImageFont.load("./fonts/6x10.pil")
try:
sports_info = self.readSportsCSV(league)
except:
pass
buff_size = 20
for team in team_info:
if league == 'PGA' or league =='LPGA':
pga_small = ImageFont.load("./fonts/4x6.pil")
try:
if league == 'PGA':
player_img = Image.open('logos/pga_rank/' + team['photo'].split('/')[-1].split('&')[0])
elif league == 'LPGA':
player_img = Image.open('logos/lpga_rank/' + team['photo'].split('/')[-1])
player_img.thumbnail((9000,16))
try:
img.paste(player_img, (x_offset, 0), mask=player_img)
except:
img.paste(player_img, (x_offset, 0))
x_offset += player_img.size[0] + 2
except:
pass
if league == 'LPGA':
if str(abs(team['rank_change'])) != '-' and str(abs(team['rank_change'])) != '0':
if int(team['rank_change']) > 0:
rank_change_img = self.textImage(str(abs(team['rank_change'])), font, r = 0, g = 255, b = 0)
elif int(team['rank_change']) < 0:
rank_change_img = self.textImage(str(abs(team['rank_change'])), font, r = 255, g = 0, b = 0)
elif league == 'PGA':
if str(team['rank_change']) != '-':
if int(team['rank_change']) > 0:
rank_change_img = self.textImage(str(abs(int(team['rank_change']))), font, r = 0, g = 255, b = 0)
elif int(team['rank_change']) < 0:
rank_change_img = self.textImage(str(abs(int(team['rank_change']))), font, r = 255, g = 0, b = 0)
x_offset2 = x_offset
country_img = Image.open('logos/ufc_countries/' + team['country'].split('/')[-1].split('&')[0])
country_img.thumbnail((9000,11))
img.paste(country_img, (x_offset, -1))
x_offset += country_img.size[0] + 2
rank_img = self.textImage('#' + str(team['rank']), font, r = 255, g=255, b=0)
img.paste(rank_img, (x_offset, 0))
x_offset += rank_img.size[0] + 2
name_img = self.textImage(team['first_name'].upper()[0] + '. ' + team['last_name'].upper(), font, r= 255, g = 255, b = 255)
img.paste(name_img, (x_offset, 0))
x_offset += name_img.size[0] + 2
if league == 'LPGA':
if str(abs(int(team['rank_change']))) != '-' and str(abs(int(team['rank_change']))) != '0':
try:
up_img = Image.open('logos/up-tiny.png')
down_img = Image.open('logos/down-tiny.png')
if int(team['rank_change']) > 0:
img.paste(up_img, (x_offset, 3))
x_offset += up_img.size[0] + 2
elif int(team['rank_change']) < 0:
img.paste(down_img, (x_offset, 3))
x_offset += down_img.size[0] + 2
img.paste(rank_change_img, (x_offset, 0))
x_offset += rank_change_img.size[0] + 2
except:
pass
elif league == 'PGA':
if str(team['rank_change']) != '-':
try:
up_img = Image.open('logos/up-tiny.png')
down_img = Image.open('logos/down-tiny.png')
if int(team['rank_change']) > 0:
img.paste(up_img, (x_offset, 3))
x_offset += up_img.size[0] + 2
elif int(team['rank_change']) < 0:
img.paste(down_img, (x_offset, 3))
x_offset += down_img.size[0] + 2
img.paste(rank_change_img, (x_offset, 0))
x_offset += rank_change_img.size[0] + 2
except:
pass
try:
ptsgained_img = self.textImage('+'+str(team['gained_pts']), pga_small, r=0, g= 255, b=0)
ptslost_img = self.textImage(str(team['lost_pts']), pga_small, r=255, g= 0, b=0)
img.paste(ptsgained_img, (x_offset, 3))
x_offset += ptsgained_img.size[0] + 2
img.paste(ptslost_img, (x_offset, 3))
x_offset += ptslost_img.size[0] + 2
except:
pass
totalpts_img = self.textImage('Total:', pga_small, r = 255, g = 255, b = 255)
totalpts2_img = self.textImage(str(team['total_pts']), pga_small, r = 0, g = 255, b = 0)
img.paste(totalpts_img, (x_offset2, 10))
x_offset2 += totalpts_img.size[0]
img.paste(totalpts2_img, (x_offset2, 10))
x_offset2 += totalpts2_img.size[0] + 3
avgpts_img = self.textImage('Avg:', pga_small, r = 255, g = 255, b = 255)
avgpts2_img = self.textImage(str(team['avg_pts']), pga_small, r = 0, g = 0, b = 255)
img.paste(avgpts_img, (x_offset2, 10))
x_offset2 += avgpts_img.size[0]
img.paste(avgpts2_img, (x_offset2, 10))
x_offset2 += avgpts2_img.size[0] + 3
events_img = self.textImage('Events:', pga_small, r= 255, g = 255, b = 255)
events2_img = self.textImage(str(team['events_played']), pga_small, r= 255, g = 128, b = 0)
img.paste(events_img, (x_offset2, 10))
x_offset2 += events_img.size[0]
img.paste(events2_img, (x_offset2, 10))
x_offset2 += events2_img.size[0] + 3
x_offsetfinal = max(x_offset2, x_offset)
x_offset = x_offsetfinal + 15
else:
name_timage = self.textImage(team['name'].upper(), font, r = 255, g = 255, b = 0)
wins_timage = self.textImage('W:' + str(team['wins']), font, r = 0, g = 255, b = 0)
loss_timage = self.textImage('L:' + str(team['loss']), font, r = 255, g = 0, b = 0)
draw_timage = self.textImage('D:' + str(team['draw']), font, r = 0, g = 0, b = 255)
standing_timage = self.textImage('#' + str(team['standing']), font, r = 255, g = 255, b = 255)
img.paste(standing_timage, (x_offset, 3))
x_offset += (standing_timage.size[0])
try:
logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo']))
width, height = logo.size
logo2 = logo.resize((int(width/2), int(height/2)))
@ -3447,7 +3549,6 @@ class StockTicker():
except Exception as e:
pass
img.paste(name_timage, (x_offset, 3))
x_offset += (name_timage.size[0] +2)
img.paste(wins_timage, (x_offset, 3))
@ -3456,16 +3557,6 @@ class StockTicker():
x_offset += (loss_timage.size[0] +2)
img.paste(draw_timage, (x_offset, 3))
x_offset += (draw_timage.size[0]+10)
# x_offset += max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0])
#img.paste(points_timage, (x_offset, 14))
# img.paste(standing_timage, (x_offset, 22))
# x_offset += standing_timage.size[0]
# if name_timage.size[0] > max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0]:
# x_offset += name_timage.size[0] - (max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0])
# x_offset += buff_size
x_offset += 25
img1 = img.crop((0,0,x_offset ,16))