getjokeimage
This commit is contained in:
parent
341afa233e
commit
14c21a8f1d
101
stockTicker.py
101
stockTicker.py
@ -5,7 +5,7 @@
|
|||||||
# stockTicker can not be copied and/or distributed without the express
|
# stockTicker can not be copied and/or distributed without the express
|
||||||
# permission of Fintic
|
# permission of Fintic
|
||||||
|
|
||||||
|
import random
|
||||||
import sys, select
|
import sys, select
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
@ -6086,6 +6086,105 @@ class StockTicker():
|
|||||||
return self.stitchImage(image_list)
|
return self.stitchImage(image_list)
|
||||||
|
|
||||||
|
|
||||||
|
def getJokesImage(self):
|
||||||
|
|
||||||
|
f = open('csv/jokes_settings.json', 'r')
|
||||||
|
jokes_settings = json.load(f)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
if jokes_settings['title']:
|
||||||
|
title_img = self.openImage('feature_titles/jokes.png')
|
||||||
|
image_list = [title_img]
|
||||||
|
else:
|
||||||
|
image_list = []
|
||||||
|
|
||||||
|
font = ImageFont.load("./fonts/BonusCoffee-14.pil")
|
||||||
|
small_font = ImageFont.load("./fonts/5x8.pil")
|
||||||
|
|
||||||
|
colours = { 'White':(255,255,255),
|
||||||
|
'Red':(255,0,0),
|
||||||
|
'Green':(0,255,0),
|
||||||
|
'Dark Green':(0,100,0),
|
||||||
|
'Blue':(0,0,255),
|
||||||
|
'Purple':(145,0,255),
|
||||||
|
'Pink':(255,0,255),
|
||||||
|
'Yellow':(255,255,0),
|
||||||
|
'Orange':(255,130,0),
|
||||||
|
'Gold':(255,190,0),
|
||||||
|
'Cyan':(0,255,255)}
|
||||||
|
|
||||||
|
if len(jokes_settings['jokes']) > 0:
|
||||||
|
try:
|
||||||
|
for joke in jokes_settings['jokes']:
|
||||||
|
random_color = random.choice(list(colours.keys()))
|
||||||
|
r,g,b = colours[random_color]
|
||||||
|
random_number = str(random.randint(1, 8)) + '.png'
|
||||||
|
emoji = self.openImage('logos/emojis/emoji' + random_number)
|
||||||
|
category_icon = self.openImage('logos/emojis/category.png')
|
||||||
|
category = self.textImage(joke['category'], small_font, r=255, g=255,b=255)
|
||||||
|
if joke['safe']:
|
||||||
|
safe = self.textImage('Safe', small_font, r=255, g=255, b=0)
|
||||||
|
else:
|
||||||
|
safe = self.textImage('Unsafe', small_font, r=255, g=0, b=0)
|
||||||
|
if joke['type'] == 'twopart':
|
||||||
|
joke1 = self.textImage(joke['setup'].replace('\n', ' '), font, int(r),int(g),int(b))
|
||||||
|
random_color = random.choice(list(colours.keys()))
|
||||||
|
r,g,b = colours[random_color]
|
||||||
|
joke2 = self.textImage(joke['delivery'].replace('\n', ' '), font, int(r), int(g), int(b))
|
||||||
|
else:
|
||||||
|
joke1 = self.textImage(joke['joke'].replace('\n', ' '), font, int(r), int(g), int(b))
|
||||||
|
joke2 = None
|
||||||
|
try:
|
||||||
|
true_flags = [key for key, value in joke['flags'].items() if value]
|
||||||
|
flags = ", ".join(true_flags)
|
||||||
|
flags_final = self.textImage(flags, small_font, r=255, g=145, b=0)
|
||||||
|
except:
|
||||||
|
flags_final = None
|
||||||
|
pass
|
||||||
|
if flags_final != None:
|
||||||
|
flags_icon = self.openImage('logos/emojis/flags.png')
|
||||||
|
else:
|
||||||
|
flags_icon = None
|
||||||
|
x_offset = 10
|
||||||
|
if joke2 != None:
|
||||||
|
try:
|
||||||
|
img = Image.new('RGB', (20 + emoji.size[0] + 5 + max(joke1.size[0], category_icon.size[0] + 2 + category.size[0] + 5 + safe.size[0] + 5 + flags_icon.size[0] + 2 + flags_final.size[0] + 5) + joke2.size[0], 32))
|
||||||
|
except:
|
||||||
|
img = Image.new('RGB', (20 + emoji.size[0] + 5 + max(joke1.size[0], category_icon.size[0] + 2 + category.size[0] + 5 + safe.size[0] + 5) + joke2.size[0], 32))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
img = Image.new('RGB', (20 + emoji.size[0] + 5 + max(joke1.size[0], category_icon.size[0] + 2 + category.size[0] + 5 + safe.size[0] + 5 + flags_icon.size[0] + 2 + flags_final.size[0] + 5), 32))
|
||||||
|
except:
|
||||||
|
img = Image.new('RGB', (20 + emoji.size[0] + 5 + max(joke1.size[0], category_icon.size[0] + 2 + category.size[0] + 5 + safe.size[0] + 5), 32))
|
||||||
|
img.paste(emoji, (x_offset, 3))
|
||||||
|
x_offset += emoji.size[0] + 5
|
||||||
|
x_offset2 = x_offset
|
||||||
|
img.paste(joke1, (x_offset, 2))
|
||||||
|
x_offset += joke1.size[0]
|
||||||
|
img.paste(category_icon, (x_offset2, 20))
|
||||||
|
x_offset2 += category_icon.size[0] + 2
|
||||||
|
img.paste(category, (x_offset2, 20))
|
||||||
|
x_offset2 += category.size[0] + 5
|
||||||
|
img.paste(safe, (x_offset2, 20))
|
||||||
|
x_offset2 += safe.size[0] + 5
|
||||||
|
try:
|
||||||
|
img.paste(flags_icon, (x_offset2, 20))
|
||||||
|
x_offset2 += flags_icon.size[0] + 2
|
||||||
|
img.paste(flags_final, (x_offset2, 20))
|
||||||
|
x_offset2 += flags_final.size[0] + 5
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
img.paste(joke2, (max(x_offset, x_offset2), 18))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
image_list.append(img)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return self.stitchImage(image_list)
|
||||||
|
|
||||||
|
|
||||||
def ip_viewer(self):
|
def ip_viewer(self):
|
||||||
|
|
||||||
font = ImageFont.load("./fonts/6x10.pil")
|
font = ImageFont.load("./fonts/6x10.pil")
|
||||||
|
Loading…
Reference in New Issue
Block a user