added ufc to getleagueimage

This commit is contained in:
Justin 2023-04-23 19:05:10 +08:00 committed by GitHub
parent 862d925857
commit 9267429734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2720,9 +2720,8 @@ class StockTicker():
img = Image.new('RGB', (10000, 32))
league_info = leagues_info[league]
try:
league_logo = Image.open('logos/sports/league_logos/{}.png'.format(league)).convert('RGB')
league_logo = Image.open('logos/sports/league_logos/{}.png'.format(league))
if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU') or (league == 'LIV') or (league == 'NASCAR') or (league == 'F1'):
x_offset += self.blank.size[0]
else:
@ -2731,246 +2730,404 @@ class StockTicker():
except:
pass
small_font = ImageFont.load("./fonts/5x7.pil")
med_font = ImageFont.load("./fonts/7x14B.pil")
large_font = ImageFont.load("./fonts/9x18B.pil")
extra_small_font = ImageFont.load("./fonts/4x6.pil")
try:
sports_info = self.readSportsCSV(league)
except:
pass
med_font = ImageFont.load("./fonts/7x14B.pil")
large_font = ImageFont.load("./fonts/9x18B.pil")
extra_small_font = ImageFont.load("./fonts/4x6.pil")
buff_size = 25
for match in league_info:
if league == 'UFC':
try:
small_font = ImageFont.load("./fonts/6x10.pil")
date_img = self.textImage(league_info[0]['date'], small_font, r=0,g=150,b=255)
eventname_img = self.textImage(league_info[0]['name'].upper(), med_font, r=255, g=0, b=0)
venue_img = self.textImage(league_info[0]['venue'], small_font, r=255, g=255, b=0)
city_img = self.textImage(league_info[0]['city'], small_font, r=255, g=255, b=255)
try:
country_img = self.textImage(league_info[0]['country'], small_font, r=255, g=128, b=0)
except:
pass
broadcast_img = self.textImage(league_info[0]['broadcast'], small_font, r=255, g=0, b=0)
time_img = self.textImage(league_info[0]['time'], small_font, r =0, g=150, b=255)
dateEvent = match['date'].replace('-', '.')
date_timage = self.textImage(dateEvent, small_font, r=255, g=255, b=255)
try:
img.paste(country_img, (x_offset + venue_img.size[0] + 5 + city_img.size[0] +5, 13))
except:
country_img = 0
pass
img.paste(eventname_img, (x_offset, 0))
img.paste(city_img, (x_offset+ venue_img.size[0] + 5, 13))
img.paste(venue_img, (x_offset,13))
img.paste(broadcast_img, (x_offset + date_img.size[0] + 5 + time_img.size[0] + 5, 23))
img.paste(date_img, (x_offset, 23))
img.paste(time_img, (x_offset + date_img.size[0] + 5, 23))
try:
x_offset = 5 + max(x_offset + eventname_img.size[0], x_offset + venue_img.size[0] + 5 + city_img.size[0] + 5 + country_img.size[0], x_offset + date_img.size[0] + 5 + time_img.size[0] + 5 + broadcast_img.size[0])
except:
x_offset = 5 + max(x_offset + eventname_img.size[0], x_offset + venue_img.size[0] + 5 + city_img.size[0] + 5, x_offset + date_img.size[0] + 5 + time_img.size[0] + 5 + broadcast_img.size[0])
if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU') or (league == 'LIV') or (league == 'NASCAR') or (league == 'F1'):
event = match['event']
venue = match['venue']
city = match['city']
country = match['country']
season = match['season']
for fight in league_info[0]['fights']:
try:
if time != 'past':
fighter1_img = Image.open('logos/ufc/{}.png'.format(fight['fighter1id']))
elif time == 'past':
fighter1_img = Image.open('logos/ufc_past/{}.png'.format(fight['fighter1id']))
#fighter1_img.thumbnail((9000,32))
except:
fighter1_img = Image.open('logos/unknown.png')
pass
try:
if time != 'past':
fighter2_img = Image.open('logos/ufc/{}.png'.format(fight['fighter2id']))
elif time == 'past':
fighter2_img = Image.open('logos/ufc_past/{}.png'.format(fight['fighter2id']))
#fighter2_img.thumbnail((9000,32))
except:
fighter2_img = Image.open('logos/unknown.png')
pass
weight_img = self.textImage(fight['weight_div'].upper(), extra_small_font, r=255,g=255,b=255)
age1_img = self.textImage(fight['fighter1age'], extra_small_font, r=255,g=255,b=255)
age2_img = self.textImage(fight['fighter2age'], extra_small_font, r=255,g=255,b=255)
age_img = self.textImage('AGE', extra_small_font, r=255,g=0,b=0)
height1_img = self.textImage(fight['fighter1height'], extra_small_font, r=255,g=255,b=255)
height2_img = self.textImage(fight['fighter2height'], extra_small_font, r=255,g=255,b=255)
height_img = self.textImage('HEIGHT', extra_small_font, r=255,g=0,b=0)
if (time != 'future') and (league != 'LIV'):
golf_standings1 = match['golf_standings'][::2]
golf_standings2 = match['golf_standings'][1::2]
elif (time!= 'future') and (league == 'LIV'):
golf_standings1 = match['golf_standings'][0][::2]
golf_standings2 = match['golf_standings'][0][1::2]
golf_standings1_teams = match['golf_standings'][1][::2]
golf_standings2_teams = match['golf_standings'][1][1::2]
weight1_img = self.textImage(fight['fighter1weight'], extra_small_font, r=255,g=255,b=255)
weight2_img = self.textImage(fight['fighter2weight'], extra_small_font, r=255,g=255,b=255)
weights_img = self.textImage('WEIGHT', extra_small_font, r=255,g=0,b=0)
img.paste(league_logo, (x_offset, 0))
x_offset += league_logo.size[0] + 2
reach1_img = self.textImage(fight['fighter1reach'], extra_small_font, r=255,g=255,b=255)
reach2_img = self.textImage(fight['fighter2reach'], extra_small_font, r=255,g=255,b=255)
reach_img = self.textImage('REACH', extra_small_font, r=255,g=0,b=0)
if time == 'future':
name1_img = self.textImage(fight['fighter1name'], extra_small_font, r=255,g=255,b=255)
record1_img = self.textImage(fight['fighter1record'], extra_small_font, r=255, g=255, b=255)
event_timage = self.textImage(event, med_font, r=255, g=255, b=0)
venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0)
city_timage = self.textImage(city, small_font, r=255, g=255, b=255)
country_timage = self.textImage(country, small_font, r=255, g=255, b=255)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255)
season_timage = self.textImage(season, small_font, r=255, g=255, b=255)
name2_img = self.textImage(fight['fighter2name'], extra_small_font, r=255,g=255,b=255)
record2_img = self.textImage(fight['fighter2record'], extra_small_font, r=255, g=255, b=255)
#date
img.paste(date1_timage, (x_offset + 2, 26))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 3, 26))
#event
img.paste(event_timage, (x_offset + 2, 0))
#venue
img.paste(venue_timage,(x_offset + 2, 16))
#country
img.paste(country_timage,(x_offset + event_timage.size[0] + 5,5))
#city
img.paste(city_timage,(x_offset + 15 + venue_timage.size[0], 16))
#season
img.paste(season1_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20,26))
img.paste(season_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0],26))
x_offset += max(2 + event_timage.size[0] + country_timage.size[0] + 5, 2 + venue_timage.size[0] + city_timage.size[0] + 15, 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0] + season_timage.size[0] + 3)
x_offset += buff_size
else:
event_timage = self.textImage(event, med_font, r=255, g=255, b=0)
venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0)
city_timage = self.textImage(city, small_font, r=255, g=255, b=255)
country_timage = self.textImage(country, small_font, r=255, g=255, b=255)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255)
season_timage = self.textImage(season, small_font, r=255, g=255, b=255)
#date
img.paste(date1_timage, (x_offset + 2, 26))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 3, 26))
#event
img.paste(event_timage, (x_offset + 2, 0))
#venue
img.paste(venue_timage,(x_offset + 2, 16))
#country
img.paste(country_timage,(x_offset + event_timage.size[0] + 5,5))
#city
img.paste(city_timage,(x_offset + 15 + venue_timage.size[0], 16))
#season
img.paste(season1_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20,26))
img.paste(season_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0],26))
x_offset += max(2 + event_timage.size[0] + country_timage.size[0] + 5, 2 + venue_timage.size[0] + city_timage.size[0] + 15, 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0] + season_timage.size[0] + 3)
x_offset2 = x_offset
for each_player in golf_standings1:
symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0)
img.paste(symbol1_timage, (x_offset + 5, 7))
golf_standings1_timage = self.textImage(each_player, small_font, r=255, g=255, b=255)
img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 7))
x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7)
for each_player2 in golf_standings2:
symbol2_timage = self.textImage('|', small_font, r=255, g=255, b=0)
img.paste(symbol2_timage, (x_offset2 + 5, 20))
golf_standings2_timage = self.textImage(each_player2, small_font, r=255, g=255, b=255)
img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 20))
x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7)
if league == 'LIV':
if x_offset >= x_offset2:
x_offset += 10
x_offset2 = x_offset
if time != 'past':
odds1_img = self.textImage(fight['fighter1odds'], extra_small_font, r=0, g=255, b=0)
#odds2_img = self.textImage(fight['fighter2odds'], extra_small_font, r=0, g=255, b=0)
elif time == 'past':
if fight['fighter1win']:
win1_img = self.textImage('WIN', extra_small_font, r=0, g=255, b=0)
else:
x_offset2 += 10
x_offset = x_offset2
win1_img = self.textImage('LOSS', extra_small_font, r=0, g=255, b=0)
for each_team in golf_standings1_teams:
symbol1_timage = self.textImage('|', small_font, r=0, g=255, b=0)
max_fighter1_pic = max(fighter1_img.size[0], name1_img.size[0], record1_img.size[0])
draw = ImageDraw.Draw(img, "RGBA")
img.paste(fighter1_img, (x_offset + int(max_fighter1_pic/2) - int(fighter1_img.size[0]/2), 0), mask=fighter1_img)
country1_img = Image.open('logos/ufc_countries/{}'.format(fight['fighter1country'].split('/')[-1].split('&')[0]))
country1_img.thumbnail((9000,12))
img.paste(country1_img,(x_offset, 0))
draw.rectangle([(x_offset,32),(x_offset + max(name1_img.size[0],record1_img.size[0])-4,21)], fill=(5,5,5,200))
draw.text((x_offset + int(max_fighter1_pic/2) - int(name1_img.size[0]/2),21), fight['fighter1name'], fill=(255,255,255),font=extra_small_font)
#img.paste(name1_img, (x_offset + int(max_fighter1_pic/2) - int(name1_img.size[0]/2),21))
draw.text((x_offset + int(max_fighter1_pic/2) - int(record1_img.size[0]/2),27), fight['fighter1record'], fill=(255,255,0),font=extra_small_font)
#img.paste(record1_img, (x_offset + int(max_fighter1_pic/2) - int(record1_img.size[0]/2), 27))
x_offset += max(fighter1_img.size[0], name1_img.size[0], record1_img.size[0])
widest = x_offset + int(max(weight_img.size[0], age1_img.size[0] + 3 + age_img.size[0] + 3 + age2_img.size[0], height1_img.size[0] + 3 + height_img.size[0] + 3 + height2_img.size[0], weight1_img.size[0] + 3 + weights_img.size[0] + 3 + weight2_img.size[0], reach1_img.size[0] + 3 + reach_img.size[0] + 3 + reach2_img.size[0])/2)
largest = max(age_img.size[0],weights_img.size[0],height_img.size[0],reach_img.size[0])
img.paste(weight_img,(widest - int(weight_img.size[0]/2), 0))
if time != 'past':
draw.text((widest - int(weight_img.size[0]/2) - odds1_img.size[0] - 2,0), fight['fighter1odds'], fill=(0,255,0),font=extra_small_font)
# img.paste(odds1_img, (widest - int(weight_img.size[0]/2) - odds1_img.size[0] - 2,0))
elif time == 'past':
if fight['fighter1win']:
draw.text((widest - int(weight_img.size[0]/2) - win1_img.size[0] - 2,0), 'WIN', fill=(0,255,0),font=extra_small_font)
else:
draw.text((widest - int(weight_img.size[0]/2) - win1_img.size[0] - 2,0), 'LOSS', fill=(255,0,0),font=extra_small_font)
img.paste(age1_img,(widest - int(largest/2) - age1_img.size[0] - 3, 7))
img.paste(age_img,(widest - int(age_img.size[0]/2),7))
img.paste(age2_img, (widest + int(largest/2) + 3, 7))
img.paste(height1_img,(widest - int(largest/2) - height1_img.size[0] - 3, 13))
img.paste(height_img,(widest - int(height_img.size[0]/2),13))
img.paste(height2_img, (widest + int(largest/2) + 3, 13))
img.paste(weight1_img,(widest - int(largest/2) - weight1_img.size[0] - 3, 19))
img.paste(weights_img,(widest - int(weights_img.size[0]/2),19))
img.paste(weight2_img, (widest + int(largest/2) + 3, 19))
img.paste(reach1_img,(widest - int(largest/2) - reach1_img.size[0] - 3, 25))
img.paste(reach_img,(widest - int(reach_img.size[0]/2),25))
img.paste(reach2_img, (widest + int(largest/2) + 3, 25))
x_offset = widest + widest - x_offset + 2
max_fighter2_pic = max(fighter2_img.size[0], name2_img.size[0], record2_img.size[0])
img.paste(fighter2_img, (x_offset + int(max_fighter2_pic/2) - int(fighter2_img.size[0]/2), 0), mask=fighter2_img)
draw.rectangle([(x_offset,32),(x_offset + max(name2_img.size[0],record2_img.size[0])-4,21)], fill=(5,5,5,200))
draw.text((x_offset + int(max_fighter2_pic/2) - int(name2_img.size[0]/2),21), fight['fighter2name'], fill=(255,255,255),font=extra_small_font)
#img.paste(name1_img, (x_offset + int(max_fighter1_pic/2) - int(name1_img.size[0]/2),21))
draw.text((x_offset + int(max_fighter2_pic/2) - int(record2_img.size[0]/2),27), fight['fighter2record'], fill=(255,255,0),font=extra_small_font)
#img.paste(record1_img, (x_offset + int(max_fighter1_pic/2) - int(record1_img.size[0]/2), 27))
x_offset += max(fighter2_img.size[0], name2_img.size[0], record2_img.size[0]) + 25
if time != 'past':
draw.text((widest + int(weight_img.size[0]/2) + 2,0), fight['fighter2odds'], fill=(0,255,0),font=extra_small_font)
#img.paste(odds2_img, (widest + int(weight_img.size[0]/2) + 2,0))
elif time == 'past':
if fight['fighter2win']:
draw.text((widest + int(weight_img.size[0]/2) + 2,0), 'WIN', fill=(0,255,0),font=extra_small_font)
else:
draw.text((widest + int(weight_img.size[0]/2) + 2,0), 'LOSS', fill=(255,0,0),font=extra_small_font)
country2_img = Image.open('logos/ufc_countries/{}'.format(fight['fighter2country'].split('/')[-1].split('&')[0]))
country2_img.thumbnail((9000,12))
img.paste(country2_img,(x_offset-country2_img.size[0]-25, 0))
except:
pass
# DONT FORGET TO CHANGE DIRECTORY FOR PAST UFC GAMES
else:
small_font = ImageFont.load("./fonts/5x7.pil")
for match in league_info:
dateEvent = match['date'].replace('-', '.')
date_timage = self.textImage(dateEvent, small_font, r=255, g=255, b=255)
if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU') or (league == 'LIV') or (league == 'NASCAR') or (league == 'F1'):
event = match['event']
venue = match['venue']
city = match['city']
country = match['country']
season = match['season']
if (time != 'future') and (league != 'LIV'):
golf_standings1 = match['golf_standings'][::2]
golf_standings2 = match['golf_standings'][1::2]
elif (time!= 'future') and (league == 'LIV'):
golf_standings1 = match['golf_standings'][0][::2]
golf_standings2 = match['golf_standings'][0][1::2]
golf_standings1_teams = match['golf_standings'][1][::2]
golf_standings2_teams = match['golf_standings'][1][1::2]
img.paste(league_logo, (x_offset, 0))
x_offset += league_logo.size[0] + 2
if time == 'future':
event_timage = self.textImage(event, med_font, r=255, g=255, b=0)
venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0)
city_timage = self.textImage(city, small_font, r=255, g=255, b=255)
country_timage = self.textImage(country, small_font, r=255, g=255, b=255)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255)
season_timage = self.textImage(season, small_font, r=255, g=255, b=255)
#date
img.paste(date1_timage, (x_offset + 2, 26))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 3, 26))
#event
img.paste(event_timage, (x_offset + 2, 0))
#venue
img.paste(venue_timage,(x_offset + 2, 16))
#country
img.paste(country_timage,(x_offset + event_timage.size[0] + 5,5))
#city
img.paste(city_timage,(x_offset + 15 + venue_timage.size[0], 16))
#season
img.paste(season1_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20,26))
img.paste(season_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0],26))
x_offset += max(2 + event_timage.size[0] + country_timage.size[0] + 5, 2 + venue_timage.size[0] + city_timage.size[0] + 15, 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0] + season_timage.size[0] + 3)
x_offset += buff_size
else:
event_timage = self.textImage(event, med_font, r=255, g=255, b=0)
venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0)
city_timage = self.textImage(city, small_font, r=255, g=255, b=255)
country_timage = self.textImage(country, small_font, r=255, g=255, b=255)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255)
season_timage = self.textImage(season, small_font, r=255, g=255, b=255)
#date
img.paste(date1_timage, (x_offset + 2, 26))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 3, 26))
#event
img.paste(event_timage, (x_offset + 2, 0))
#venue
img.paste(venue_timage,(x_offset + 2, 16))
#country
img.paste(country_timage,(x_offset + event_timage.size[0] + 5,5))
#city
img.paste(city_timage,(x_offset + 15 + venue_timage.size[0], 16))
#season
img.paste(season1_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20,26))
img.paste(season_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0],26))
x_offset += max(2 + event_timage.size[0] + country_timage.size[0] + 5, 2 + venue_timage.size[0] + city_timage.size[0] + 15, 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0] + season_timage.size[0] + 3)
x_offset2 = x_offset
for each_player in golf_standings1:
symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0)
img.paste(symbol1_timage, (x_offset + 5, 7))
golf_standings1_timage = self.textImage(each_team, small_font, r=255, g=255, b=255)
golf_standings1_timage = self.textImage(each_player, small_font, r=255, g=255, b=255)
img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 7))
x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7)
for each_team2 in golf_standings2_teams:
symbol2_timage = self.textImage('|', small_font, r=0, g=255, b=0)
for each_player2 in golf_standings2:
symbol2_timage = self.textImage('|', small_font, r=255, g=255, b=0)
img.paste(symbol2_timage, (x_offset2 + 5, 20))
golf_standings2_timage = self.textImage(each_team2, small_font, r=255, g=255, b=255)
golf_standings2_timage = self.textImage(each_player2, small_font, r=255, g=255, b=255)
img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 20))
x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7)
if league == 'LIV':
if x_offset >= x_offset2:
x_offset += 10
x_offset2 = x_offset
else:
x_offset2 += 10
x_offset = x_offset2
if x_offset >= x_offset2:
x_offset += buff_size
else:
x_offset = x_offset2
x_offset += buff_size
else:
strHomeTeam = match['home_team']
strAwayTeam = match['away_team']
if time != 'future':
intHomeScore = str(match['home_score'])
intAwayScore = str(match['away_score'])
try:
home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strHomeTeam]['logo']))
except Exception as e:
home_logo = self.textImage(strHomeTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255)
try:
away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strAwayTeam]['logo']))
except Exception as e:
away_logo = self.textImage(strAwayTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255)
img.paste(away_logo, (x_offset,0))
x_offset += away_logo.size[0] + 4
if time == 'future':
#img.paste(date_timage, (x_offset+5, 0))
try:
h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', ''))
except:
pass
try:
a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', ''))
except:
pass
vs_timage = self.textImage('vs', med_font, r = 255, g = 255, b = 255, h_buff = 5)
try:
hc_timage = self.textImage(sports_info[strHomeTeam]['code'], med_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
except Exception as e:
hc_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
try:
ac_timage = self.textImage(sports_info[strAwayTeam]['code'], med_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
except Exception as e:
ac_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
for each_team in golf_standings1_teams:
symbol1_timage = self.textImage('|', small_font, r=0, g=255, b=0)
img.paste(symbol1_timage, (x_offset + 5, 7))
golf_standings1_timage = self.textImage(each_team, small_font, r=255, g=255, b=255)
img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 7))
x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7)
for each_team2 in golf_standings2_teams:
symbol2_timage = self.textImage('|', small_font, r=0, g=255, b=0)
img.paste(symbol2_timage, (x_offset2 + 5, 20))
golf_standings2_timage = self.textImage(each_team2, small_font, r=255, g=255, b=255)
img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 20))
x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7)
vs_size = vs_timage.size[0] + ac_timage.size[0] + hc_timage.size[0]
main_offset = 5 + x_offset + int(max(vs_size, date_timage.size[0])/2)
img.paste(date_timage, (main_offset - int(date_timage.size[0]/2), 0))
img.paste(vs_timage, (main_offset - int(vs_timage.size[0]/2),9))
img.paste(ac_timage, (main_offset - int(vs_timage.size[0]/2) - ac_timage.size[0], 9))
img.paste(hc_timage, (main_offset + int(vs_timage.size[0]/2),9))
x_offset = (main_offset + max(int(date_timage.size[0]/2), int(vs_timage.size[0]/2) + hc_timage.size[0]) + 6)
if x_offset >= x_offset2:
x_offset += buff_size
else:
x_offset = x_offset2
x_offset += buff_size
else:
score_image = self.textImage(intAwayScore + '-' + intHomeScore, large_font, h_buff = 5, r = 255, g = 255, b = 255)
strHomeTeam = match['home_team']
strAwayTeam = match['away_team']
if time != 'future':
intHomeScore = str(match['home_score'])
intAwayScore = str(match['away_score'])
try:
h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', ''))
except:
pass
try:
a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', ''))
except:
pass
try:
hc_timage = self.textImage(sports_info[strHomeTeam]['code'], small_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strHomeTeam]['logo']))
except Exception as e:
hc_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
home_logo = self.textImage(strHomeTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255)
try:
ac_timage = self.textImage(sports_info[strAwayTeam]['code'], small_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strAwayTeam]['logo']))
except Exception as e:
ac_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
away_logo = self.textImage(strAwayTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255)
img.paste(away_logo, (x_offset,0))
x_offset += away_logo.size[0] + 4
if time == 'future':
start_time = match['time']
#img.paste(date_timage, (x_offset+5, 0))
time_img = self.textImage(start_time, small_font, r=255,g=255,b=255)
try:
h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', ''))
except:
pass
try:
a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', ''))
except:
pass
vs_timage = self.textImage('vs', med_font, r = 255, g = 255, b = 255, h_buff = 5)
try:
hc_timage = self.textImage(sports_info[strHomeTeam]['code'], med_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
except Exception as e:
hc_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
try:
ac_timage = self.textImage(sports_info[strAwayTeam]['code'], med_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
except Exception as e:
ac_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
vs_timage = self.textImage('VS', extra_small_font, r = 255, g = 255, b = 255)
vs_size = vs_timage.size[0] + ac_timage.size[0] + hc_timage.size[0]
vs_size = hc_timage.size[0] + ac_timage.size[0] + vs_timage.size[0]
main_offset = 5 + x_offset + int(max(vs_size, date_timage.size[0])/2)
main_offset = x_offset + int(max(vs_size, date_timage.size[0], score_image.size[0])/2)
img.paste(date_timage,(main_offset - int(date_timage.size[0]/2),0))
img.paste(vs_timage,(main_offset - int(vs_timage.size[0]/2),10))
img.paste(ac_timage, (main_offset - int(vs_timage.size[0]/2) - ac_timage.size[0], 9))
img.paste(score_image, (main_offset - int(score_image.size[0]/2), 15))
if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
ua_image = Image.new("RGB", (ac_timage.size[0] -2, 1))
ua_image1 = ImageDraw.Draw(ua_image)
ua_image1.line((0,0,ac_timage.size[0]-2,0), fill="red", width = 0)
img.paste(ua_image, (main_offset - int(vs_timage.size[0]/2)-ac_timage.size[0], ac_timage.size[1]+7))
img.paste(hc_timage, (main_offset + int(vs_timage.size[0]/2),9))
if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
u_image = Image.new("RGB", (hc_timage.size[0] -2, 1))
u_image1 = ImageDraw.Draw(u_image)
u_image1.line((0,0,hc_timage.size[0]-2,0), fill="red", width = 0)
img.paste(u_image, (main_offset + int(vs_timage.size[0]/2), hc_timage.size[1]+7))
x_offset = (main_offset + max(int(date_timage.size[0]/2), int(vs_timage.size[0]/2) + hc_timage.size[0], int(score_image.size[0]/2)) + 4)
img.paste(time_img, (main_offset - int(time_img.size[0]/2), 26))
img.paste(date_timage, (main_offset - int(date_timage.size[0]/2), 0))
img.paste(vs_timage, (main_offset - int(vs_timage.size[0]/2),9))
img.paste(ac_timage, (main_offset - int(vs_timage.size[0]/2) - ac_timage.size[0], 9))
img.paste(hc_timage, (main_offset + int(vs_timage.size[0]/2),9))
x_offset = (main_offset + max(int(date_timage.size[0]/2), int(vs_timage.size[0]/2) + hc_timage.size[0]) + 6)
else:
score_image = self.textImage(intAwayScore + '-' + intHomeScore, large_font, h_buff = 5, r = 255, g = 255, b = 255)
try:
h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', ''))
except:
pass
try:
a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', ''))
except:
pass
try:
hc_timage = self.textImage(sports_info[strHomeTeam]['code'], small_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
except Exception as e:
hc_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
try:
ac_timage = self.textImage(sports_info[strAwayTeam]['code'], small_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
except Exception as e:
ac_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255)
vs_timage = self.textImage('VS', extra_small_font, r = 255, g = 255, b = 255)
vs_size = hc_timage.size[0] + ac_timage.size[0] + vs_timage.size[0]
main_offset = x_offset + int(max(vs_size, date_timage.size[0], score_image.size[0])/2)
img.paste(date_timage,(main_offset - int(date_timage.size[0]/2),0))
img.paste(vs_timage,(main_offset - int(vs_timage.size[0]/2),10))
img.paste(ac_timage, (main_offset - int(vs_timage.size[0]/2) - ac_timage.size[0], 9))
img.paste(score_image, (main_offset - int(score_image.size[0]/2), 15))
if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
ua_image = Image.new("RGB", (ac_timage.size[0] -2, 1))
ua_image1 = ImageDraw.Draw(ua_image)
ua_image1.line((0,0,ac_timage.size[0]-2,0), fill="red", width = 0)
img.paste(ua_image, (main_offset - int(vs_timage.size[0]/2)-ac_timage.size[0], ac_timage.size[1]+7))
img.paste(hc_timage, (main_offset + int(vs_timage.size[0]/2),9))
if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
u_image = Image.new("RGB", (hc_timage.size[0] -2, 1))
u_image1 = ImageDraw.Draw(u_image)
u_image1.line((0,0,hc_timage.size[0]-2,0), fill="red", width = 0)
img.paste(u_image, (main_offset + int(vs_timage.size[0]/2), hc_timage.size[1]+7))
x_offset = (main_offset + max(int(date_timage.size[0]/2), int(vs_timage.size[0]/2) + hc_timage.size[0], int(score_image.size[0]/2)) + 4)
img.paste(home_logo, (x_offset,0))
x_offset += home_logo.size[0]
x_offset += buff_size
img.paste(home_logo, (x_offset,0))
x_offset += home_logo.size[0]
x_offset += buff_size
img = img.crop((0,0,x_offset ,32))
imgs.append(img)
except Exception as e:
pass
# logf = open('log.txt', "a")
@ -2982,9 +3139,6 @@ class StockTicker():
# 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)