global stock image added
This commit is contained in:
parent
ee62f88110
commit
8e28f6cd29
214
stockTicker.py
214
stockTicker.py
@ -107,7 +107,7 @@ class StockTicker():
|
||||
#sys.exit()
|
||||
self.points = True # display crypto change in points or percent
|
||||
|
||||
self.functions = {'Stocks': self.getStockImage, 'Crypto': self.getCryptoImage, 'Forex': self.getForexImage, 'Sector Performance': self.getSectorImage, 'Inspirational Quotes': self.getQuotesImage,
|
||||
self.functions = {'Stocks': self.getStockImage, 'Global Stocks': self.getGlobalStockImage, 'Crypto': self.getCryptoImage, 'Forex': self.getForexImage, 'Sector Performance': self.getSectorImage, 'Inspirational Quotes': self.getQuotesImage,
|
||||
'Daily Forecast':self.getDailyWeatherImage, 'Current Weather': self.getTodayWeatherImage, 'Jokes': self.getJokesImage, 'Place (Reddit)': self.getPlaceImage,
|
||||
'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'),
|
||||
@ -119,7 +119,7 @@ class StockTicker():
|
||||
'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')}
|
||||
|
||||
self.JSONs = {'Stocks': 'csv/stocks_settings.json', 'Crypto': 'csv/crypto_settings.json', 'Forex': 'csv/forex_settings.json', 'Jokes': 'csv/jokes_settings.json', 'Inspirational Quotes': 'csv/quotes_settings.json',
|
||||
self.JSONs = {'Stocks': 'csv/stocks_settings.json', 'Global Stocks': 'csv/globalstocks_settings.json', 'Crypto': 'csv/crypto_settings.json', 'Forex': 'csv/forex_settings.json', 'Jokes': 'csv/jokes_settings.json', 'Inspirational Quotes': 'csv/quotes_settings.json',
|
||||
'Daily Forecast':'csv/daily_weather.json', 'Current Weather': 'csv/current_weather.json', 'Commodities':'csv/commodities_settings.json', 'Indices': 'csv/indices_settings.json',
|
||||
'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',
|
||||
@ -3694,7 +3694,214 @@ class StockTicker():
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
self.blank = Image.new('RGB', (10, 32))
|
||||
return finalDisplayImage
|
||||
|
||||
|
||||
def getGlobalStockImage(self):
|
||||
|
||||
f = open('csv/globalstocks_settings.json', 'r')
|
||||
all_globalstocks_settings = json.load(f)
|
||||
f.close()
|
||||
if all_globalstocks_settings['title']:
|
||||
title_img = self.openImage('feature_titles/globalstocks.png')
|
||||
image_list = [title_img]
|
||||
image_list.append(self.blank)
|
||||
else:
|
||||
image_list = []
|
||||
if all_globalstocks_settings['chart']:
|
||||
try:
|
||||
f = open('csv/portfolio_global_settings.json', 'r')
|
||||
portfolio_settings = json.load(f)['symbols']
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if all_globalstocks_settings['display_name']:
|
||||
names = True
|
||||
else:
|
||||
names = False
|
||||
except:
|
||||
names = False
|
||||
pass
|
||||
|
||||
stock_info = all_globalstocks_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() #TEXT
|
||||
except:
|
||||
ticker = symbol
|
||||
else:
|
||||
ticker = symbol
|
||||
|
||||
arrow, change = self.getArrow(change)
|
||||
|
||||
percent_change = '%.2f' % abs(float(info['percent_change'])) + '%'
|
||||
point_change = '%.2f' % abs(change)
|
||||
|
||||
current = '%.2f' % float(info['current']) #TEXT
|
||||
|
||||
if not all_globalstocks_settings['percent']:
|
||||
percent_change = False
|
||||
if not all_globalstocks_settings['point']:
|
||||
point_change = False
|
||||
|
||||
midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT
|
||||
|
||||
if all_globalstocks_settings['logos']:
|
||||
try:
|
||||
ticker = symbol
|
||||
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'global_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
|
||||
|
||||
try:
|
||||
if all_globalstocks_settings['lohivol']:
|
||||
font = ImageFont.load("./fonts/5x8.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_img.size[0] + daylow_t_img.size[0], dayhi_img.size[0] + dayhi_t_img.size[0],
|
||||
vol_img.size[0] + vol_t_img.size[0]) + 5, 32))
|
||||
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, 12))
|
||||
lohivol_img.paste(dayhi_img, (dayhi_t_img.size[0], 12))
|
||||
lohivol_img.paste(vol_t_img, (0, 21))
|
||||
lohivol_img.paste(vol_img, (vol_t_img.size[0], 21))
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if all_globalstocks_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], days_img.size[0], days2_img.size[0]) + 7 +
|
||||
max(shares_img.size[0], shares2_img.size[0], value2_img.size[0], value_img.size[0]) + 7 +
|
||||
max(pnlpercent_img.size[0], pnlpercent2_img.size[0], pnlchange_img.size[0], pnlchange2_img.size[0]) + 7 +
|
||||
max(daypercent_img.size[0], daypercent2_img.size[0], daychange_img.size[0], daychange2_img.size[0]) + 15, 32))
|
||||
|
||||
img.paste(cost_img, (x_offset, 0))
|
||||
img.paste(cost2_img, (x_offset, 8))
|
||||
img.paste(days_img, (x_offset, 16))
|
||||
img.paste(days2_img, (x_offset, 24))
|
||||
x_offset += max(cost_img.size[0], cost2_img.size[0], days_img.size[0], days2_img.size[0]) + 7
|
||||
|
||||
img.paste(shares_img, (x_offset, 0))
|
||||
img.paste(shares2_img, (x_offset, 8))
|
||||
img.paste(value_img, (x_offset, 16))
|
||||
img.paste(value2_img, (x_offset, 24))
|
||||
x_offset += max(shares_img.size[0], shares2_img.size[0], value2_img.size[0], value_img.size[0]) + 7
|
||||
|
||||
img.paste(pnlpercent_img, (x_offset, 0))
|
||||
img.paste(pnlpercent2_img, (x_offset, 8))
|
||||
img.paste(pnlchange_img, (x_offset, 16))
|
||||
img.paste(pnlchange2_img, (x_offset, 24))
|
||||
x_offset += max(pnlpercent_img.size[0], pnlpercent2_img.size[0], pnlchange_img.size[0], pnlchange2_img.size[0]) + 7
|
||||
|
||||
img.paste(daypercent_img, (x_offset, 0))
|
||||
img.paste(daypercent2_img, (x_offset, 8))
|
||||
img.paste(daychange_img, (x_offset,16))
|
||||
img.paste(daychange2_img, (x_offset, 24))
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
image_list.append(stitchedStock)
|
||||
try:
|
||||
if all_globalstocks_settings['lohivol']:
|
||||
try:
|
||||
image_list.append(lohivol_img)
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if all_globalstocks_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)
|
||||
|
||||
return finalDisplayImage
|
||||
|
||||
|
||||
|
||||
def getNewsImage(self):
|
||||
|
||||
@ -10002,6 +10209,9 @@ class StockTicker():
|
||||
|
||||
elif msg == 'IQ':
|
||||
self.scrollFunctionsAnimated(['quotes', 'quotes'],animation = 'traditional')
|
||||
|
||||
elif msg == 'GS':
|
||||
self.scrollFunctionsAnimated(['globalstocks', 'globalstocks'],animation = 'traditional')
|
||||
|
||||
elif msg == 'A': #everything
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user