get global stock image prof

This commit is contained in:
Justin 2023-09-26 17:43:07 +08:00 committed by GitHub
parent 8e28f6cd29
commit b1add6ae8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,7 +114,7 @@ class StockTicker():
'News':self.getNewsImage, 'Custom Messages': self.getUserMessages, 'Commodities': self.getCommoditiesImage, 'Indices': self.getIndicesImage, 'Movies': self.getMoviesImage, 'Gainers, Losers, Active': self.getMarketImage,
'Economic Calendar': self.getEconomicImage, 'IPO Calendar':self.getIpoImage, 'IPO Calendar Prof':self.getIpoProfessional, 'Economic Calendar Prof': self.getEconomicProfessional, 'Gainers, Losers, Active Prof': self.getMarketProfessional,
'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional, 'Jokes Prof': self.getJokesProfessional, 'Place (Reddit) Prof': self.getPlaceImageProfessional, 'Inspirational Quotes Prof': self.getQuotesProfessional,
'Stocks Prof': self.getStockProfessional, 'Global Stocks Prof': self.getGlobalStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional, 'Jokes Prof': self.getJokesProfessional, 'Place (Reddit) Prof': self.getPlaceImageProfessional, 'Inspirational Quotes Prof': self.getQuotesProfessional,
'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional, 'Sector Performance Prof': self.getSectorProfessional,
'Daily Forecast Prof':self.getDailyWeatherProfessional, 'Sports (Team Stats) Prof':lambda : self.getLeagueTableProfessional('NHL'), 'Sports (Upcoming Games) Prof': lambda : self.getLeagueProfessional('NHL', 'future'),
'Sports (Past Games) Prof': lambda : self.getLeagueProfessional('NBA', 'past'), 'Custom Messages Prof': self.getUserMessagesProfessional, 'Custom Images Prof': self.getUserImagesProfessional, 'Movies Prof': self.getMoviesProfessional, 'Sports (Live Games) Prof': lambda : self.getLeagueProfessional('NBA', 'live')}
@ -124,7 +124,7 @@ class StockTicker():
'Sports (Team Stats)': 'csv/league_tables.json', 'Sports (Past Games)': 'csv/past_games.json', 'IPO Calendar': 'csv/ipo_settings.json', 'Economic Calendar': 'csv/economic_settings.json',
'Sports (Upcoming Games)': 'csv/upcoming_games.json', 'Sports (Live Games)': 'csv/live_games.json', 'Movies': 'csv/movie_settings.json', 'Clock 1': 'csv/clock1_settings.json', 'Clock 2': 'csv/clock2_settings.json', 'World Clock': 'csv/worldclock_settings.json',
'News':'csv/news_settings.json', 'Custom Images': 'csv/image_settings.json', 'Custom GIFs': 'csv/GIF_settings.json', 'Custom Messages': 'csv/message_settings.json', 'Clock 1 Prof': 'csv/clock1_settings.json', 'World Clock Prof': 'csv/worldclock_settings.json',
'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json', 'Jokes Prof': 'csv/jokes_settings.json', 'Clock 2 Prof': 'csv/clock2_settings.json',
'Stocks Prof': 'csv/stocks_settings.json', 'Global Stocks Prof': 'csv/globalstocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json', 'Jokes Prof': 'csv/jokes_settings.json', 'Clock 2 Prof': 'csv/clock2_settings.json',
'Current Weather Prof': 'csv/current_weather.json', 'News Prof':'csv/news_settings.json', 'Commodities Prof':'csv/commodities_settings.json', 'Indices Prof': 'csv/indices_settings.json',
'Daily Forecast Prof':'csv/daily_weather.json', 'Sports (Team Stats) Prof': 'csv/league_tables.json', 'Sports (Upcoming Games) Prof': 'csv/upcoming_games.json', 'Sports (Past Games) Prof': 'csv/past_games.json', 'Custom Messages Prof': 'csv/message_settings.json', 'Custom Images Prof': 'csv/image_settings.json', 'Movies Prof': 'csv/movie_settings.json', 'Sports (Live Games) Prof': 'csv/live_games.json', 'IPO Calendar Prof': 'csv/ipo_settings.json', 'Economic Calendar Prof': 'csv/economic_settings.json',
'Gainers, Losers, Active':'csv/market_settings.json', 'Gainers, Losers, Active Prof':'csv/market_settings.json', 'Sector Performance':'csv/sector_settings.json', 'Sector Performance Prof':'csv/sector_settings.json', 'Place (Reddit)':'csv/place_settings.json', 'Place (Reddit) Prof':'csv/place_settings.json'}
@ -3901,6 +3901,216 @@ class StockTicker():
return finalDisplayImage
def getGlobalStockProfessional(self):
self.blank = Image.new('RGB', (0, 16))
f = open('csv/globalstocks_settings.json', 'r')
all_stocks_settings = json.load(f)
f.close()
if all_stocks_settings['title']:
title_img = self.openImage('feature_titles/small_feature_titles/globalstocks.png')
image_list = [title_img, Image.new('RGB', (5, 16))]
image_list.append(self.blank)
else:
image_list = []
if all_stocks_settings['chart']:
try:
f = open('csv/portfolio_global_settings.json', 'r')
portfolio_settings = json.load(f)['symbols']
f.close()
except:
pass
try:
if all_stocks_settings['display_name']:
names = True
else:
names = False
except:
names = False
pass
stock_info = all_stocks_settings['symbols']
symbols = list(stock_info.keys())
for i, symbol in enumerate(symbols):
try:
info = stock_info[symbol]
change = float(info['change'])#TEXT
if names:
try:
ticker = info['name'].upper() + 'display_name' #TEXT
except:
ticker = symbol
else:
ticker = symbol
arrow, change = self.getArrow(change, professional=True)
if all_stocks_settings["percent"]:
change = '%.2f' % abs(float(info['percent_change'])) + '%'
else:
change = '%.2f' % abs(change)
current = '%.2f' % float(info['current']) #TEXT
midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
if all_stocks_settings['logos']:
ticker = symbol
try:
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'global_stocks')
logo = Image.open(os.path.join(logos_path, ticker + '.png'))
# half the size of the logo
width, height = logo.size
logo = logo.resize((int(width/2), int(height/2)))
stitchedStock = self.stitchImage([logo,midFrame])
except Exception as e:
stitchedStock = midFrame
else:
stitchedStock = midFrame
try:
if all_stocks_settings['lohivol']:
font = ImageFont.load("./fonts/4x6.pil")
try:
day_low = '%.2f' % float(info['day_low'])
day_high = '%.2f' % float(info['day_high'])
volume = info['volume']
daylow_img = self.textImage(day_low, font, r=0, g=255, b=0)
daylow_t_img = self.textImage('Lo', font, r=255, g=255, b=255)
dayhi_img = self.textImage(day_high, font, r=0,g=255,b=0)
dayhi_t_img = self.textImage('Hi', font, r=255,g=255,b=255)
vol_img = self.textImage(volume, font, r=0,g=255,b=0)
vol_t_img = self.textImage('Vol', font, r=255,g=255,b=255)
lohivol_img = Image.new('RGB', (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0] + vol_img.size[0] + 8, 16))
lohivol_img.paste(daylow_t_img, (0, 3))
lohivol_img.paste(daylow_img, (daylow_t_img.size[0],3))
lohivol_img.paste(dayhi_t_img, (0, 9))
lohivol_img.paste(dayhi_img, (dayhi_t_img.size[0], 9))
lohivol_img.paste(vol_t_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0])+2, 3))
lohivol_img.paste(vol_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0], 3))
except:
pass
except:
pass
try:
if all_stocks_settings['chart'] and (symbol in portfolio_settings): #IF USER INPUTTED PORTFOLIO SETTINGS, DISPLAY PORTFOLIO INFO
try:
cost = portfolio_settings[symbol]['cost']
day = portfolio_settings[symbol]['day']
day_start = datetime.strptime(str(day), "%Y-%m-%d")
day_today = datetime.strptime(datetime.now(pytz.utc).strftime("%Y-%m-%d"), "%Y-%m-%d")
day = str((day_today - day_start).days)
shares = portfolio_settings[symbol]['shares']
original_value = float(cost) * float(shares)
new_value = float(info['current']) * float(shares)
value_day_change_percent = ((float(info['percent_change'])/100) * new_value)
font = ImageFont.load("./fonts/5x8.pil")
cost_img = self.textImage('Cost', font, r = 255, g = 255 , b = 255)
cost2_img = self.textImage(cost, font, r = 0, g = 255, b = 0)
shares_img = self.textImage('Shares', font, r = 255, g = 255 , b = 255)
shares2_img = self.textImage(shares, font, r = 0, g = 255, b = 0)
pnlchange = new_value - original_value
pnlpercent = ((new_value - original_value) / original_value) * 100
pnlpercent_img = self.textImage('P/L%', font, r = 255, g = 255 , b = 255)
if pnlpercent >= 0:
pnlpercent2_img = self.textImage(str('%.2f' % abs(pnlpercent)) + '%', font, r = 0, g = 255, b = 0)
else:
pnlpercent2_img = self.textImage(str('%.2f' % abs(pnlpercent)) + '%', font, r = 255, g = 0, b = 0)
daypercent_img = self.textImage('Day%', font, r = 255, g = 255 , b = 255)
if float(info['percent_change']) >= 0:
daypercent2_img = self.textImage(str('%.2f' % abs(float(info['percent_change']))) +'%', font, r = 0, g = 255, b = 0)
else:
daypercent2_img = self.textImage(str('%.2f' % abs(float(info['percent_change'])))+'%', font, r = 255, g = 0, b = 0)
days_img = self.textImage('Days', font, r = 255, g = 255 , b = 255)
days2_img = self.textImage(day, font, r = 0, g = 255, b = 0)
value_img = self.textImage('Value', font, r = 255, g = 255 , b = 255)
value2_img = self.textImage(str('%.2f' % abs(original_value)), font, r = 0, g = 255, b = 0)
pnlchange_img = self.textImage('P/L$', font, r = 255, g = 255 , b = 255)
if pnlchange >= 0:
pnlchange2_img = self.textImage(str('%.2f' % abs(pnlchange)), font, r = 0, g = 255, b = 0)
else:
pnlchange2_img = self.textImage(str('%.2f' % abs(pnlchange)), font, r = 255, g = 0, b = 0)
daychange_img = self.textImage('Day$', font, r = 255, g = 255 , b = 255)
if value_day_change_percent >= 0:
daychange2_img = self.textImage(str('%.2f' % abs(value_day_change_percent)), font, r = 0, g = 255, b = 0)
else:
daychange2_img = self.textImage(str('%.2f' % abs(value_day_change_percent)), font, r = 255, g = 0, b = 0)
x_offset = 0
img = Image.new('RGB', (max(cost_img.size[0], cost2_img.size[0]) + 5 + max(days_img.size[0], days2_img.size[0]) + 5 +
max(shares_img.size[0], shares2_img.size[0]) + 5 + max(value2_img.size[0], value_img.size[0]) + 5 +
max(pnlpercent_img.size[0], pnlpercent2_img.size[0]) + 5 + max(pnlchange_img.size[0], pnlchange2_img.size[0]) + 5 +
max(daypercent_img.size[0], daypercent2_img.size[0]) + 5 + max(daychange_img.size[0], daychange2_img.size[0]) + 10,16))
img.paste(cost_img, (x_offset, 1))
img.paste(cost2_img, (x_offset, 9))
x_offset += max(cost_img.size[0], cost2_img.size[0]) + 4
img.paste(days_img, (x_offset, 1))
img.paste(days2_img, (x_offset, 9))
x_offset += max(days_img.size[0], days2_img.size[0]) + 4
img.paste(shares_img, (x_offset, 1))
img.paste(shares2_img, (x_offset, 9))
x_offset += max(shares_img.size[0], shares2_img.size[0]) + 4
img.paste(value_img, (x_offset, 1))
img.paste(value2_img, (x_offset, 9))
x_offset += max(value2_img.size[0], value_img.size[0]) + 4
img.paste(pnlpercent_img, (x_offset, 1))
img.paste(pnlpercent2_img, (x_offset, 9))
x_offset += max(pnlpercent_img.size[0], pnlpercent2_img.size[0]) + 4
img.paste(pnlchange_img, (x_offset, 1))
img.paste(pnlchange2_img, (x_offset, 9))
x_offset += max(pnlchange_img.size[0], pnlchange2_img.size[0]) + 4
img.paste(daypercent_img, (x_offset, 1))
img.paste(daypercent2_img, (x_offset, 9))
x_offset += max(daypercent_img.size[0], daypercent2_img.size[0]) + 4
img.paste(daychange_img, (x_offset,1))
img.paste(daychange2_img, (x_offset, 9))
except:
pass
except:
pass
image_list.append(stitchedStock)
try:
if all_stocks_settings['lohivol']:
try:
image_list.append(lohivol_img)
except:
pass
except:
pass
try:
if all_stocks_settings['chart'] and (symbol in portfolio_settings):
try:
image_list.append(img)
except:
pass
except:
pass
image_list.append(self.blank)
except Exception as e:
pass
finalDisplayImage = self.stitchImage(image_list)
self.blank = Image.new('RGB', (10, 32))
return finalDisplayImage
def getNewsImage(self):
@ -10055,6 +10265,7 @@ class StockTicker():
sector = self.getSectorProfessional()
place = self.getPlaceImageProfessional()
quotes = self.getQuotesProfessional()
globalstocks = self.getGlobalStockProfessional()
x_offset = 0
news.paste(weather, (x_offset, 16))
@ -10099,6 +10310,8 @@ class StockTicker():
x_offset += place.size[0]
news.paste(quotes, (x_offset, 16))
x_offset += quotes.size[0]
news.paste(globalstocks, (x_offset, 16))
x_offset += globalstocks.size[0]
self.double_buffer = self.matrix.CreateFrameCanvas()
while True:
kill = stock_ticker.scrollImage(news, offset_x = 128)