added ufc to getleagueimage
This commit is contained in:
parent
862d925857
commit
9267429734
182
stockTicker.py
182
stockTicker.py
@ -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,18 +2730,176 @@ 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
|
||||
|
||||
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)
|
||||
|
||||
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])
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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:
|
||||
win1_img = self.textImage('LOSS', extra_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('-', '.')
|
||||
@ -2890,8 +3047,9 @@ class StockTicker():
|
||||
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:
|
||||
@ -2914,6 +3072,7 @@ class StockTicker():
|
||||
|
||||
main_offset = 5 + x_offset + int(max(vs_size, date_timage.size[0])/2)
|
||||
|
||||
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))
|
||||
@ -2965,12 +3124,10 @@ class StockTicker():
|
||||
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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user