This commit is contained in:
Justin 2023-04-28 19:27:47 +08:00 committed by GitHub
parent aa7a20d8f5
commit 7987fdcdbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3607,292 +3607,378 @@ class StockTicker():
buff_size = 20
for match in league_info:
if league == 'UFC':
try:
dateEvent = match['date2']
except:
dateEvent = match['date'].replace('-', '.')
if time == 'future':
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(), 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:
date_timage = self.textImage(dateEvent + ' ' + match['time'].replace("EST","").replace('PM','P').replace('AM','A').replace('CET',''), small_font, r = 255, g = 255, b = 255)
country_img = self.textImage(league_info[0]['country'], small_font, r=255, g=128, b=0)
except:
date_timage = self.textImage(dateEvent, small_font, r = 255, g = 255, b = 255)
else:
date_timage = self.textImage(dateEvent, small_font, r = 255, g = 255, b = 255)
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)
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']
try:
img.paste(country_img, (x_offset + eventname_img.size[0] + 2, 2))
except:
country_img = 0
pass
img.paste(eventname_img, (x_offset, 0))
img.paste(city_img, (x_offset + date_img.size[0] + 3 + time_img.size[0] + 3 + broadcast_img.size[0] + 7 + venue_img.size[0] + 3, 10))
img.paste(venue_img, (x_offset + date_img.size[0] + 3 + time_img.size[0] + 3 + broadcast_img.size[0] + 7,10))
img.paste(broadcast_img, (x_offset + date_img.size[0] + 3 + time_img.size[0] + 3, 10))
img.paste(date_img, (x_offset, 10))
img.paste(time_img, (x_offset + date_img.size[0] + 3, 10))
try:
x_offset = 10 + max(x_offset + eventname_img.size[0] + 2 + country_img.size[0], x_offset + date_img.size[0] + 3 + time_img.size[0] + 3 + broadcast_img.size[0] + 7 + venue_img.size[0] + 3 + city_img.size[0])
except:
x_offset = 10 + max(x_offset + eventname_img.size[0], x_offset + date_img.size[0] + 3 + time_img.size[0] + 3 + broadcast_img.size[0] + 7 + venue_img.size[0] + 3 + city_img.size[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]
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,16))
except:
fighter1_img = Image.open('logos/unknown.png')
fighter1_img.thumbnail((9000,16))
pass
img.paste(league_logo2, (x_offset, 0))
x_offset += league_logo2.size[0] + 5
draw = ImageDraw.Draw(img, "RGBA")
name1_img = self.textImage(fight['fighter1name'].split(' ',1)[0][0] + '.' + fight['fighter1name'].split(' ',1)[1], small_font, r=255,g=255,b=255)
max_fighter1pic = max(name1_img.size[0],fighter1_img.size[0])
if time == 'future':
event_timage = self.textImage(event, small_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)
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)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
img.paste(fighter1_img, (x_offset + int(max_fighter1pic/2) - int(fighter1_img.size[0]/2), 0), mask=fighter1_img)
draw.rectangle([(x_offset,16),(x_offset + name1_img.size[0]-4,10)], fill=(5,5,5,200))
draw.text((x_offset + int(max_fighter1pic/2) - int(name1_img.size[0]/2),10), fight['fighter1name'].split(' ',1)[0][0] + '.' + fight['fighter1name'].split(' ',1)[1], fill=(255,255,255),font=small_font)
try:
country1_img = Image.open('logos/ufc_countries/{}'.format(fight['fighter1country'].split('/')[-1].split('&')[0]))
country1_img.thumbnail((9000,8))
img.paste(country1_img,(x_offset, 0))
except:
pass
x_offset += max_fighter1pic
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,16))
except:
fighter2_img = Image.open('logos/unknown.png')
fighter2_img.thumbnail((9000,16))
pass
#event
img.paste(event_timage, (x_offset, 1))
#venue
img.paste(venue_timage,(x_offset, 9))
x_offset += (max(event_timage.size[0], venue_timage.size[0]) + 5)
#date
img.paste(date1_timage, (x_offset, 1))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 2, 1))
#city
img.paste(city_timage,(x_offset, 9))
#country
img.paste(country_timage,(x_offset + city_timage.size[0] + 7,9))
#season
img.paste(season1_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + 5,1))
img.paste(season_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5,1))
x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0])
x_offset += (buff_size - 10)
else:
event_timage = self.textImage(event, small_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)
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)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
weight_img = self.textImage(fight['weight_div'].upper(), small_font, r=255,g=0,b=0)
vs_img = self.textImage('VS', small_font, r=255,g=255,b=255)
#event
img.paste(event_timage, (x_offset, 1))
#venue
img.paste(venue_timage,(x_offset, 9))
x_offset += (max(event_timage.size[0], venue_timage.size[0]) + 5)
#date
img.paste(date1_timage, (x_offset, 1))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 2, 1))
#city
img.paste(city_timage,(x_offset, 9))
#country
img.paste(country_timage,(x_offset + city_timage.size[0] + 7,9))
#season
img.paste(season1_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + 5,1))
img.paste(season_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5,1))
x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0])
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, 1))
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, 1))
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, 9))
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, 9))
x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7)
if league == 'LIV':
if x_offset >= x_offset2:
x_offset += 5
x_offset2 = x_offset
if time != 'past':
odds1_img = self.textImage(fight['fighter1odds'], small_font, r=0, g=255, b=0)
odds2_img = self.textImage(fight['fighter2odds'], small_font, r=0, g=255, b=0)
max_middle = max(vs_img.size[0] + odds1_img.size[0] + odds2_img.size[0], weight_img.size[0])
img.paste(weight_img, (x_offset + int(max_middle/2) - int(weight_img.size[0]/2), 1))
img.paste(odds1_img, (x_offset + int(max_middle/2) - int(vs_img.size[0]/2) - odds1_img.size[0],8))
img.paste(vs_img, (x_offset + int(max_middle/2) - int(vs_img.size[0]/2),8))
img.paste(odds2_img, (x_offset + int(max_middle/2) + int(vs_img.size[0]/2),8))
elif time == 'past':
if fight['fighter1win']:
win1_img = self.textImage('WIN', small_font, r=0, g=255, b=0)
win2_img = self.textImage('LOSS', small_font, r=255, g=0, b=0)
elif not fight['fighter1win'] and not fight['fighter2win']:
win1_img = self.textImage('DRAW', small_font, r=80, g=80, b=80)
win2_img = self.textImage('DRAW', small_font, r=80, g=80, b=80)
else:
x_offset2 += 5
x_offset = x_offset2
win1_img = self.textImage('LOSS', small_font, r=255, g=0, b=0)
win2_img = self.textImage('WIN', small_font, r=0, g=255, b=0)
max_middle = max(vs_img.size[0] + win1_img.size[0] + win2_img.size[0], weight_img.size[0])
img.paste(weight_img, (x_offset + int(max_middle/2) - int(weight_img.size[0]/2), 1))
img.paste(win1_img, (x_offset + int(max_middle/2) - int(vs_img.size[0]/2) - int(win1_img.size[0]),8))
img.paste(vs_img, (x_offset + int(max_middle/2) - int(vs_img.size[0]/2),8))
img.paste(win2_img, (x_offset + int(max_middle/2) + int(vs_img.size[0]/2),8))
x_offset += max_middle
for each_team in golf_standings1_teams:
symbol1_timage = self.textImage('|', small_font, r=0, g=255, b=0)
name2_img = self.textImage(fight['fighter2name'].split(' ',1)[0][0] + '.' + fight['fighter2name'].split(' ',1)[1], small_font, r=255,g=255,b=255)
max_fighter2pic = max(name2_img.size[0],fighter2_img.size[0])
img.paste(fighter2_img, (x_offset + int(max_fighter2pic/2) - int(fighter2_img.size[0]/2), 0), mask=fighter2_img)
draw.rectangle([(x_offset,16),(x_offset + name2_img.size[0]-4,10)], fill=(5,5,5,200))
draw.text((x_offset + int(max_fighter2pic/2) - int(name2_img.size[0]/2),10), fight['fighter2name'].split(' ',1)[0][0] + '.' + fight['fighter2name'].split(' ',1)[1], fill=(255,255,255),font=small_font)
try:
country2_img = Image.open('logos/ufc_countries/{}'.format(fight['fighter2country'].split('/')[-1].split('&')[0]))
country2_img.thumbnail((9000,8))
img.paste(country2_img,(x_offset + max_fighter2pic - country2_img.size[0] - 2, 0))
except:
pass
x_offset += max_fighter2pic + 15
except:
pass
# DONT FORGET TO CHANGE DIRECTORY FOR PAST UFC GAMES
else:
for match in league_info:
try:
dateEvent = match['date2']
except:
dateEvent = match['date'].replace('-', '.')
if time == 'future':
try:
date_timage = self.textImage(dateEvent + ' ' + match['time'].replace("EST","").replace('PM','P').replace('AM','A').replace('CET',''), small_font, r = 255, g = 255, b = 255)
except:
date_timage = self.textImage(dateEvent, small_font, r = 255, g = 255, b = 255)
else:
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_logo2, (x_offset, 0))
x_offset += league_logo2.size[0] + 5
if time == 'future':
event_timage = self.textImage(event, small_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)
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)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
#event
img.paste(event_timage, (x_offset, 1))
#venue
img.paste(venue_timage,(x_offset, 9))
x_offset += (max(event_timage.size[0], venue_timage.size[0]) + 5)
#date
img.paste(date1_timage, (x_offset, 1))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 2, 1))
#city
img.paste(city_timage,(x_offset, 9))
#country
img.paste(country_timage,(x_offset + city_timage.size[0] + 7,9))
#season
img.paste(season1_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + 5,1))
img.paste(season_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5,1))
x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0])
x_offset += (buff_size - 10)
else:
event_timage = self.textImage(event, small_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)
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)
date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171)
#event
img.paste(event_timage, (x_offset, 1))
#venue
img.paste(venue_timage,(x_offset, 9))
x_offset += (max(event_timage.size[0], venue_timage.size[0]) + 5)
#date
img.paste(date1_timage, (x_offset, 1))
img.paste(date_timage, (x_offset + date1_timage.size[0] + 2, 1))
#city
img.paste(city_timage,(x_offset, 9))
#country
img.paste(country_timage,(x_offset + city_timage.size[0] + 7,9))
#season
img.paste(season1_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + 5,1))
img.paste(season_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5,1))
x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0])
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, 1))
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, 1))
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, 9))
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, 9))
x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7)
if league == 'LIV':
if x_offset >= x_offset2:
x_offset += 5
x_offset2 = x_offset
else:
x_offset2 += 5
x_offset = x_offset2
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, 1))
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, 1))
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, 9))
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, 9))
x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7)
if x_offset >= x_offset2:
x_offset += (buff_size - 10)
else:
x_offset = x_offset2
x_offset += (buff_size - 10)
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']))
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, small_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, small_font, r = 255, g = 255, b = 255)
error = False
img.paste(away_logo1, (x_offset,0))
x_offset += (away_logo1.size[0] + 2)
if time == 'future':
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'], font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
except:
hc_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
try:
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))
except:
ac_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
vs_timage = self.textImage('vs', font, r = 255, g = 255, b = 255, h_buff = 5)
x_offsetdate2 = x_offset + int((hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0])/2)- int(date_timage.size[0]/2)
if date_timage.size[0] > (ac_timage.size[0] + vs_timage.size[0] + hc_timage.size[0]):
x_offset3 = x_offset + int(date_timage.size[0]/2)
img.paste(date_timage, (x_offset,0))
x_offset += date_timage.size[0]
img.paste(ac_timage, (x_offset3 - int(ac_timage.size[0]) - int(vs_timage.size[0]/2), 5))
img.paste(vs_timage, (x_offset3 - int(vs_timage.size[0]/2), 5))
img.paste(hc_timage, (x_offset3 + int(vs_timage.size[0]/2), 5))
else:
img.paste(date_timage, (x_offsetdate2,0))
x_offsetdate2 += date_timage.size[0]
img.paste(ac_timage, (x_offset, 5))
x_offset += ac_timage.size[0]
img.paste(vs_timage, (x_offset, 5))
x_offset += vs_timage.size[0]
img.paste(hc_timage, (x_offset, 5))
x_offset += hc_timage.size[0]
if x_offset >= x_offset2:
x_offset += (buff_size - 10)
else:
x_offset = x_offset2
x_offset += (buff_size - 10)
score_image = self.textImage(intAwayScore + '-' + intHomeScore, 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
else:
strHomeTeam = match['home_team']
strAwayTeam = match['away_team']
try:
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))
except:
hc_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
try:
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))
except:
ac_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
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']))
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, small_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, small_font, r = 255, g = 255, b = 255)
error = False
img.paste(away_logo1, (x_offset,0))
x_offset += (away_logo1.size[0] + 2)
if time == 'future':
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'], font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
except:
hc_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
try:
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))
except:
ac_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
vs_timage = self.textImage('vs', font, r = 255, g = 255, b = 255, h_buff = 5)
x_offsetdate2 = x_offset + int((hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0])/2)- int(date_timage.size[0]/2)
if date_timage.size[0] > (ac_timage.size[0] + vs_timage.size[0] + hc_timage.size[0]):
x_offset3 = x_offset + int(date_timage.size[0]/2)
img.paste(date_timage, (x_offset,0))
x_offset += date_timage.size[0]
img.paste(ac_timage, (x_offset3 - int(ac_timage.size[0]) - int(vs_timage.size[0]/2), 5))
img.paste(vs_timage, (x_offset3 - int(vs_timage.size[0]/2), 5))
img.paste(hc_timage, (x_offset3 + int(vs_timage.size[0]/2), 5))
else:
x_offsetdate2 = x_offset + ac_timage.size[0] + int(score_image.size[0]/2)- int(date_timage.size[0]/2)
img.paste(date_timage, (x_offsetdate2,0))
x_offsetdate2 += date_timage.size[0]
#img.paste(date_timage, (x_offset+20+int((score_image.size[0] - date_timage.size[0])/2),0))
img.paste(ac_timage, (x_offset, 5))
if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
ua_image = Image.new("RGB", (ac_timage.size[0] -3, 1))
ua_image1 = ImageDraw.Draw(ua_image)
ua_image1.line((0,0,ac_timage.size[0]-3,0), fill="red", width = 0)
img.paste(ua_image, (x_offset, ac_timage.size[1]+4))
x_offset += ac_timage.size[0]
img.paste(vs_timage, (x_offset, 5))
x_offset += vs_timage.size[0]
img.paste(score_image, (x_offset, 5))
x_offset += score_image.size[0]
img.paste(hc_timage, (x_offset, 5))
if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
u_image = Image.new("RGB", (hc_timage.size[0] -3, 1))
u_image1 = ImageDraw.Draw(u_image)
u_image1.line((0,0,hc_timage.size[0]-3,0), fill="red", width = 0)
img.paste(u_image, (x_offset, hc_timage.size[1]+4))
x_offset += hc_timage.size[0]
#img.paste(date_timage, (x_offsetdate2,0))
#x_offsetdate2 += date_timage.size[0]
#img.paste(ac_timage, (x_offset, 5))
#x_offset += ac_timage.size[0]
#img.paste(vs_timage, (x_offset, 5))
#x_offset += vs_timage.size[0]
#img.paste(hc_timage, (x_offset, 5))
#x_offset += hc_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(intAwayScore + '-' + intHomeScore, 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'], font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
except:
hc_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
try:
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))
except:
ac_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255)
error = True
if error:
img.paste(home_logo1, (max(x_offset + date_timage.size[0], x_offsetdate2),0))
x_offset += (home_logo1.size[0] + date_timage.size[0])
else:
img.paste(home_logo1, (max(x_offset, x_offsetdate2),0))
x_offset += home_logo1.size[0]
x_offset += buff_size
x_offsetdate2 = x_offset + ac_timage.size[0] + int(score_image.size[0]/2)- int(date_timage.size[0]/2)
img.paste(date_timage, (x_offsetdate2,0))
x_offsetdate2 += date_timage.size[0]
#img.paste(date_timage, (x_offset+20+int((score_image.size[0] - date_timage.size[0])/2),0))
img.paste(ac_timage, (x_offset, 5))
if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
ua_image = Image.new("RGB", (ac_timage.size[0] -3, 1))
ua_image1 = ImageDraw.Draw(ua_image)
ua_image1.line((0,0,ac_timage.size[0]-3,0), fill="red", width = 0)
img.paste(ua_image, (x_offset, ac_timage.size[1]+4))
x_offset += ac_timage.size[0]
img.paste(score_image, (x_offset, 5))
x_offset += score_image.size[0]
img.paste(hc_timage, (x_offset, 5))
if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore):
u_image = Image.new("RGB", (hc_timage.size[0] -3, 1))
u_image1 = ImageDraw.Draw(u_image)
u_image1.line((0,0,hc_timage.size[0]-3,0), fill="red", width = 0)
img.paste(u_image, (x_offset, hc_timage.size[1]+4))
x_offset += hc_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]))
if error:
img.paste(home_logo1, (max(x_offset + date_timage.size[0], x_offsetdate2),0))
x_offset += (home_logo1.size[0] + date_timage.size[0])
else:
img.paste(home_logo1, (max(x_offset, x_offsetdate2),0))
x_offset += home_logo1.size[0]
x_offset += buff_size
x_offset += 20
x_offset += 20 #INDENT THIS OR NO?
img = img.crop((0,0,x_offset ,16))
imgs.append(img)
except:
pass
return self.stitchImage(imgs)