From 50538251aa1b43dbd0fb509e6bd820eedc8eae7e Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 17 Jul 2023 16:45:22 +0800 Subject: [PATCH] jokes professional --- stockTicker.py | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/stockTicker.py b/stockTicker.py index 589d258..f4825e9 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -6184,6 +6184,105 @@ class StockTicker(): return self.stitchImage(image_list) + + def getJokesProfessional(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/small_feature_titles/jokes.png') + image_list = [title_img] + else: + image_list = [] + + font = ImageFont.load("./fonts/6x10.pil") + small_font = ImageFont.load("./fonts/4x6.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/small_emojis/emoji' + random_number) + category_icon = self.openImage('logos/emojis/small_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/small_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], 16)) + 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], 16)) + 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), 16)) + 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), 16)) + img.paste(emoji, (x_offset, 0)) + x_offset += emoji.size[0] + 5 + x_offset2 = x_offset + img.paste(joke1, (x_offset, 0)) + x_offset += joke1.size[0] + img.paste(category_icon, (x_offset2, 10)) + x_offset2 += category_icon.size[0] + 2 + img.paste(category, (x_offset2, 10)) + x_offset2 += category.size[0] + 5 + img.paste(safe, (x_offset2, 10)) + x_offset2 += safe.size[0] + 5 + try: + img.paste(flags_icon, (x_offset2, 10)) + x_offset2 += flags_icon.size[0] + 2 + img.paste(flags_final, (x_offset2, 10)) + x_offset2 += flags_final.size[0] + 5 + except: + pass + try: + img.paste(joke2, (max(x_offset, x_offset2), 6)) + except: + pass + image_list.append(img) + except: + pass + + return self.stitchImage(image_list) + def ip_viewer(self):