getsectorimage

This commit is contained in:
Justin 2023-08-15 15:39:32 +08:00 committed by GitHub
parent 4773141ad0
commit d4b68ab517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,7 +66,7 @@ class StockTicker():
#sys.exit() #sys.exit()
self.points = True # display crypto change in points or percent self.points = True # display crypto change in points or percent
self.functions = {'Stocks': self.getStockImage, 'Crypto': self.getCryptoImage, 'Forex': self.getForexImage, self.functions = {'Stocks': self.getStockImage, 'Crypto': self.getCryptoImage, 'Forex': self.getForexImage, 'Sector Performance': self.getSectorImage,
'Daily Forecast':self.getDailyWeatherImage, 'Current Weather': self.getTodayWeatherImage, 'Jokes': self.getJokesImage, 'Daily Forecast':self.getDailyWeatherImage, 'Current Weather': self.getTodayWeatherImage, 'Jokes': self.getJokesImage,
'Sports (Team Stats)':lambda : self.getLeagueTableImage('premier_league'), 'Sports (Past Games)': lambda:self.getLeagueImage('NBA', 'past'), 'Sports (Team Stats)':lambda : self.getLeagueTableImage('premier_league'), 'Sports (Past Games)': lambda:self.getLeagueImage('NBA', 'past'),
'Sports (Upcoming Games)': lambda : self.getLeagueImage('NHL', 'future'), 'Sports (Live Games)': lambda: self.getLeagueImage('NBA', 'live'), 'Sports (Upcoming Games)': lambda : self.getLeagueImage('NHL', 'future'), 'Sports (Live Games)': lambda: self.getLeagueImage('NBA', 'live'),
@ -86,7 +86,7 @@ class StockTicker():
'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json', 'Jokes Prof': 'csv/jokes_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',
'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', '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', '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'} 'Gainers, Losers, Active':'csv/market_settings.json', 'Gainers, Losers, Active Prof':'csv/market_settings.json', 'Sector Performance':'csv/sector_settings.json'}
def openImage(self, image_file): def openImage(self, image_file):
@ -921,7 +921,6 @@ class StockTicker():
w1, text_height = self.get_text_dimensions(TICKER, font) w1, text_height = self.get_text_dimensions(TICKER, font)
w2, text_height = self.get_text_dimensions(CURRENT, font) w2, text_height = self.get_text_dimensions(CURRENT, font)
text_width_current = max(w1,w2) text_width_current = max(w1,w2)
img = Image.new('RGB', (text_width_current +1000 , 32)) img = Image.new('RGB', (text_width_current +1000 , 32))
@ -934,17 +933,15 @@ class StockTicker():
d.text(((w1+7), 14 - text_height), percent_change, fill=self.greenORred, font=font) d.text(((w1+7), 14 - text_height), percent_change, fill=self.greenORred, font=font)
w, h = self.get_text_dimensions(percent_change, font) w, h = self.get_text_dimensions(percent_change, font)
w1 += 7 + w w1 += 7 + w
if point_change: if point_change:
img.paste(ARROW, ((w2+ 9),18)) img.paste(ARROW, ((w2+ 9),18))
d.text(((w2+29), 16), point_change, fill=self.greenORred, font=font) d.text(((w2+29), 16), point_change, fill=self.greenORred, font=font)
w,h = self.get_text_dimensions(point_change, font) w,h = self.get_text_dimensions(point_change, font)
w2 += 29 + w w2 += 29 + w
if not point_change and not percent_change:
img.paste(ARROW, ((w2+ 9),18))
w2 += ARROW.size[0] + 9
img = img.crop((0,0,max(w1, w2) + 8,32)) img = img.crop((0,0,max(w1, w2) + 8,32))
return img return img
@ -6937,6 +6934,51 @@ class StockTicker():
self.blank = Image.new('RGB', (10, 32)) self.blank = Image.new('RGB', (10, 32))
return finalDisplayImage return finalDisplayImage
def getSectorImage(self):
f = open('csv/sector_settings.json', 'r')
sector_settings = json.load(f)
f.close()
if sector_settings['title']:
title_img = self.openImage('feature_titles/sector.png')
image_list = [title_img]
image_list.append(self.blank)
else:
image_list = []
data_info = sector_settings['data']
data_symbols = list(data_info.keys())
for category in sector_settings['sectors']:
try:
info = data_info[category]
change = float(info['current']) #TEXT
ticker = category.upper() #TEXT
arrow, change = self.getArrow(change)
current = '%.2f' % abs(float(info['current'])) + '%' #TEXT
percent_change = False
point_change = False
midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT
if sector_settings['logos']:
try:
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks')
logo = self.openImage(os.path.join(logos_path, ticker + '.png'))
stitchedStock = self.stitchImage([logo,midFrame])
except Exception as e:
stitchedStock = midFrame
else:
stitchedStock = midFrame
image_list.append(stitchedStock)
image_list.append(self.blank)
except:
pass
finalDisplayImage = self.stitchImage(image_list)
return finalDisplayImage
def ip_viewer(self): def ip_viewer(self):
@ -7113,6 +7155,9 @@ class StockTicker():
elif msg == 'MA': # market elif msg == 'MA': # market
self.scrollFunctionsAnimated(['market', 'market'],animation = 'traditional') self.scrollFunctionsAnimated(['market', 'market'],animation = 'traditional')
elif msg == 'SE':
self.scrollFunctionsAnimated(['sector', 'sector'],animation = 'traditional')
elif msg == 'A': #everything elif msg == 'A': #everything