From d9bcdcbf04e211f8c179f9bddabf654bcd031bfe Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 30 Mar 2023 18:27:09 +0800 Subject: [PATCH] prepost prof --- stockTicker.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 4 deletions(-) diff --git a/stockTicker.py b/stockTicker.py index f43f2bc..d4060a6 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -2111,9 +2111,22 @@ class StockTicker(): except: pass + try: + if all_stocks_settings['prepost']: + try: + f = open('csv/prepost_settings.json', 'r') + prepost_settings = json.load(f) + f.close() + except: + pass + except: + pass + stock_info = all_stocks_settings['symbols'] symbols = list(stock_info.keys()) - + timenow = datetime.now(ny_zone).replace(tzinfo=None).strftime("%H:%M:%S") + weekday = datetime.now(ny_zone).replace(tzinfo=None).weekday() + for i, symbol in enumerate(symbols): try: @@ -2122,8 +2135,6 @@ class StockTicker(): change = float(info['change'])#TEXT ticker = symbol #TEXT - - arrow, change = self.getArrow(change, professional=True) if all_stocks_settings["percent"]: @@ -2158,6 +2169,71 @@ class StockTicker(): else: stitchedStock = midFrame + try: + if all_stocks_settings['prepost']: + font = ImageFont.load("./fonts/5x8.pil") + # prepost_time = prepost_settings[symbol]['time_now'] + + if ((timenow < "09:30:00" and timenow > "04:00:00") and (weekday <= 4)): #premarket + try: + preprice = '%.2f' % abs(float(prepost_settings[symbol]['Pre-market']['preprice'])) + prechange = '%.2f' % abs(float(prepost_settings[symbol]['Pre-market']['prechange'])) + prepercent = '%.2f' % abs(float(prepost_settings[symbol]['Pre-market']['prepercent'])) + + premkt_img = self.textImage('Pre-Mkt'.upper(), font, r=255, g=255, b=0) + if '-' in prepost_settings[symbol]['Pre-market']['prechange']: + preprice_img = self.textImage(preprice, font, r = 255, g = 0 , b = 0) + prechange_img = self.textImage(prechange, font, r = 255, g = 0, b = 0) + prepercent_img = self.textImage('('+prepercent + '%' + ')', font, r=255, g=0, b=0) + arrow = Image.open('logos/down-tiny.png') + else: + preprice_img = self.textImage(preprice, font, r = 0, g = 255 , b = 0) + prechange_img = self.textImage(prechange, font, r = 0, g = 255, b = 0) + prepercent_img = self.textImage('('+prepercent + '%' + ')', font, r=0, g=255, b=0) + arrow = Image.open('logos/up-tiny.png') + # time_img = self.textImage(prepost_time, font, r=255,g=255,b=255) + prepost_img = Image.new('RGB', (max(premkt_img.size[0] + prepercent_img.size[0], preprice_img.size[0] + 2 + prechange_img.size[0] + arrow.size[0]) + 10, 16)) + prepost_img.paste(premkt_img, (0,0)) + prepost_img.paste(prepercent_img, (premkt_img.size[0], 0)) + prepost_img.paste(preprice_img,(0,8)) + # prepost_img.paste(time_img, (preprice_img.size[0] + prechange_img.size[0] + 2 + arrow.size[0], 8)) + prepost_img.paste(arrow, (preprice_img.size[0],11)) + prepost_img.paste(prechange_img, (preprice_img.size[0] + arrow.size[0] + 2,8)) + except: + pass + + elif ((timenow < "04:00:00" or timenow > "16:00:00") and (weekday <= 4)): #postmarket + try: + postprice = '%.2f' % abs(float(prepost_settings[symbol]['Post-market']['postprice'])) + postchange = '%.2f' % abs(float(prepost_settings[symbol]['Post-market']['postchange'])) + postpercent = '%.2f' % abs(float(prepost_settings[symbol]['Post-market']['postpercent'])) + + postmkt_img = self.textImage('After-Hrs'.upper(), font, r=255, g=255, b=0) + if '-' in prepost_settings[symbol]['Post-market']['postchange']: + postprice_img = self.textImage(postprice, font, r = 255, g = 0, b = 0) + postchange_img = self.textImage(postchange, font, r = 255, g = 0, b = 0) + postpercent_img = self.textImage('('+postpercent +'%'+')', font, r=255, g=0, b=0) + arrow = Image.open('logos/down-tiny.png') + else: + postprice_img = self.textImage(postprice, font, r =0, g = 255 , b = 0) + postchange_img = self.textImage(postchange, font, r = 0, g = 255, b = 0) + postpercent_img = self.textImage('(' + postpercent + '%'+')', font, r=0, g=255, b=0) + arrow = Image.open('logos/up-tiny.png') + #time_img = self.textImage(prepost_time, font, r=255,g=255,b=255) + + prepost_img = Image.new('RGB', (10 + max(postmkt_img.size[0] + postpercent_img.size[0], postprice_img.size[0] + 2 + postchange_img.size[0] + arrow.size[0]) , 16)) + prepost_img.paste(postmkt_img, (0,0)) + prepost_img.paste(postpercent_img, (postmkt_img.size[0], 0)) + prepost_img.paste(postprice_img,(0,8)) + #prepost_img.paste(time_img, (0, 12)) + prepost_img.paste(arrow, (postprice_img.size[0],11)) + prepost_img.paste(postchange_img, (postprice_img.size[0] + arrow.size[0] + 2,8)) + except: + pass + + except: + pass + try: if all_stocks_settings['chart'] and (symbol in portfolio_settings): #IF USER INPUTTED PORTFOLIO SETTINGS, DISPLAY PORTFOLIO INFO try: @@ -2247,6 +2323,15 @@ class StockTicker(): pass image_list.append(stitchedStock) + + try: + if all_stocks_settings['prepost']: + try: + image_list.append(prepost_img) + except: + pass + except: + pass try: if all_stocks_settings['chart'] and (symbol in portfolio_settings): @@ -2262,7 +2347,6 @@ class StockTicker(): except Exception as e: pass finalDisplayImage = self.stitchImage(image_list) - self.blank = Image.new('RGB', (10, 32)) return finalDisplayImage