prepost prof

This commit is contained in:
Justin 2023-03-30 18:27:09 +08:00 committed by GitHub
parent df353f4a63
commit d9bcdcbf04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2111,8 +2111,21 @@ 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):
@ -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:
@ -2248,6 +2324,15 @@ class StockTicker():
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):
try:
@ -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