Compare commits
10 Commits
fb535bc82e
...
872e6a0172
Author | SHA1 | Date | |
---|---|---|---|
|
872e6a0172 | ||
|
db4fd6faa5 | ||
|
9e029407de | ||
|
b1add6ae8d | ||
|
8e28f6cd29 | ||
|
ee62f88110 | ||
|
dae16ab719 | ||
|
13d2377719 | ||
|
93a80866d2 | ||
|
58805d63c6 |
BIN
feature_titles/globalstocks.png
Normal file
After Width: | Height: | Size: 526 B |
BIN
feature_titles/small_feature_titles/globalstocks.png
Normal file
After Width: | Height: | Size: 393 B |
BIN
logos/global_stocks/0001.HK.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
logos/global_stocks/0700.HK.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
logos/global_stocks/9984.T.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
logos/global_stocks/MBG.DE.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
logos/global_stocks/MC.PA.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
logos/global_stocks/NESN.SW.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
@ -1,8 +0,0 @@
|
||||
{\rtf1\ansi\ansicpg1252\cocoartf2513
|
||||
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
||||
{\colortbl;\red255\green255\blue255;}
|
||||
{\*\expandedcolortbl;;}
|
||||
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
|
||||
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
|
||||
|
||||
\f0\fs24 \cf0 add global stock logos here }
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
10
server.py
@ -263,7 +263,7 @@ def index():
|
||||
globalstocks_settings = json.load(f)
|
||||
f.close()
|
||||
except:
|
||||
globalstocks_settings = {"feature": "Global Stocks", "speed": "medium", "speed2": "medium", "animation": "continuous", "percent": True, "point": True, "logos": True, "chart": False, "title": True, "lohivol": True, "display_name": False, "symbols": {}}
|
||||
globalstocks_settings = {"feature": "Global Stocks", "speed": "medium", "speed2": "medium", "animation": "continuous", "percent": True, "point": True, "logos": True, "chart": False, "title": True, "lohivol": True, "display_name": False, "symbols": {"0001.HK": {"current": "40.65", "change": "-0.6499977", "percent_change": "-1.5738443", "day_low": "40.65", "day_high": "41.4", "volume": "3.37M", "name": "CK Hutchison Holdings Ltd"}, "NESN.SW": {"current": "106.82", "change": "-0.3199997", "percent_change": "-0.29867435", "day_low": "106.2", "day_high": "106.92", "volume": "187K", "name": "Nestl\u00e9 S.A."}, "MBG.DE": {"current": "65.6", "change": "-0.7799988", "percent_change": "-1.1750509", "day_low": "65.26", "day_high": "66.36", "volume": "278K", "name": "Mercedes-Benz Group AG"}, "MC.PA": {"current": "701.4", "change": "-11.899963", "percent_change": "-1.6682972", "day_low": "696.8", "day_high": "705.4", "volume": "106K", "name": "LVMH Mo\u00ebt Hennessy - Louis Vuitton Soci\u00e9t\u00e9 Europ\u00e9enne"}, "9984.T": {"current": "6370.0", "change": "-54.0", "percent_change": "-0.8405978", "day_low": "6358.0", "day_high": "6470.0", "volume": "7.87M", "name": "SoftBank Group Corp."}, "0700.HK": {"current": "300.0", "change": "-4.399994", "percent_change": "-1.4454645", "day_low": "298.2", "day_high": "303.6", "volume": "14.5M", "name": "Tencent Holdings Ltd"}}}
|
||||
with open('csv/globalstocks_settings.json', 'w') as f:
|
||||
json.dump(globalstocks_settings, f)
|
||||
try:
|
||||
@ -1384,11 +1384,11 @@ def screensaver():
|
||||
elif "Grayscale Block" in data:
|
||||
screensaver_p = pexpect.spawn("sudo ./demo --led-gpio-mapping=adafruit-hat --led-rows=32 --led-cols=128 -D 5")
|
||||
elif "Clock 1" in data:
|
||||
screensaver_p = pexpect.spawn("sudo python3 clock_screensaver.py")
|
||||
screensaver_p = pexpect.spawn("python3 clock_screensaver.py")
|
||||
elif "Clock 2" in data:
|
||||
screensaver_p = pexpect.spawn("sudo python3 clock_screensaver2.py")
|
||||
screensaver_p = pexpect.spawn("python3 clock_screensaver2.py")
|
||||
elif "World Clock" in data:
|
||||
screensaver_p = pexpect.spawn("sudo python3 world_clock2.py")
|
||||
screensaver_p = pexpect.spawn("python3 world_clock2.py")
|
||||
elif "Sleep" in data:
|
||||
screensaver_p = DummyProcess()
|
||||
else: #default in case user hasnt set one yet
|
||||
@ -1876,7 +1876,7 @@ def save_globalstocks_settings(input_settings):
|
||||
current_settings = json.load(f)
|
||||
f.close()
|
||||
except:
|
||||
current_settings = {"feature": "Global Stocks", "speed": "medium", "speed2": "medium", "animation": "continuous", "percent": True, "point": True, "logos": True, "chart": False, "title": True, "lohivol": True, "display_name": False, "symbols": {}}
|
||||
current_settings = {"feature": "Global Stocks", "speed": "medium", "speed2": "medium", "animation": "continuous", "percent": True, "point": True, "logos": True, "chart": False, "title": True, "lohivol": True, "display_name": False, "symbols": {"0001.HK": {"current": "40.65", "change": "-0.6499977", "percent_change": "-1.5738443", "day_low": "40.65", "day_high": "41.4", "volume": "3.37M", "name": "CK Hutchison Holdings Ltd"}, "NESN.SW": {"current": "106.82", "change": "-0.3199997", "percent_change": "-0.29867435", "day_low": "106.2", "day_high": "106.92", "volume": "187K", "name": "Nestl\u00e9 S.A."}, "MBG.DE": {"current": "65.6", "change": "-0.7799988", "percent_change": "-1.1750509", "day_low": "65.26", "day_high": "66.36", "volume": "278K", "name": "Mercedes-Benz Group AG"}, "MC.PA": {"current": "701.4", "change": "-11.899963", "percent_change": "-1.6682972", "day_low": "696.8", "day_high": "705.4", "volume": "106K", "name": "LVMH Mo\u00ebt Hennessy - Louis Vuitton Soci\u00e9t\u00e9 Europ\u00e9enne"}, "9984.T": {"current": "6370.0", "change": "-54.0", "percent_change": "-0.8405978", "day_low": "6358.0", "day_high": "6470.0", "volume": "7.87M", "name": "SoftBank Group Corp."}, "0700.HK": {"current": "300.0", "change": "-4.399994", "percent_change": "-1.4454645", "day_low": "298.2", "day_high": "303.6", "volume": "14.5M", "name": "Tencent Holdings Ltd"}}}
|
||||
|
||||
current_settings['speed'] = input_settings['speed'].lower()
|
||||
current_settings['speed2'] = input_settings['speed2'].lower()
|
||||
|
431
stockTicker.py
@ -107,24 +107,24 @@ 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'),
|
||||
'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')}
|
||||
|
||||
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',
|
||||
'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'}
|
||||
@ -3696,6 +3696,423 @@ class StockTicker():
|
||||
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 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):
|
||||
|
||||
|
||||
@ -9848,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))
|
||||
@ -9892,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)
|
||||
@ -10003,6 +10423,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
|
||||
|
||||
#userSettings = ['display_gif', 'text', 'display_image', 'stocks', 'crypto', 'forex', 'today_weather', 'daily_weather', 'league_table', 'league_games', 'news'] # these wil be read from csv, just for demo
|
||||
|