economic calendar prof

This commit is contained in:
Justin 2023-06-26 17:31:31 +08:00 committed by GitHub
parent 45f3b7cb3b
commit 72f7530950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,7 +71,7 @@ class StockTicker():
'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,
'Economic Calendar': self.getEconomicImage, 'IPO Calendar':self.getIpoImage, 'IPO Calendar Prof':self.getIpoProfessional,
'Economic Calendar': self.getEconomicImage, 'IPO Calendar':self.getIpoImage, 'IPO Calendar Prof':self.getIpoProfessional, 'Economic Calendar Prof': self.getEconomicProfessional,
'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional,
'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional,
@ -85,7 +85,7 @@ class StockTicker():
'News':'csv/news_settings.json', 'Custom Images': 'csv/image_settings.json', 'Custom GIFs': 'csv/GIF_settings.json', 'Custom Messages': 'csv/message_settings.json',
'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_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'}
'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'}
def openImage(self, image_file):
@ -5936,6 +5936,142 @@ class StockTicker():
return self.stitchImage(image_list)
def getEconomicProfessional(self):
f = open('csv/economic_settings.json', 'r')
econ_settings = json.load(f)
f.close()
if econ_settings['title']:
title_img = self.openImage('feature_titles/small_feature_titles/economy.png')
image_list = [title_img]
else:
image_list = []
font = ImageFont.load("./fonts/5x8.pil")
small_font = ImageFont.load("./fonts/4x6.pil")
if len(econ_settings['events']) != 0:
try:
for event in econ_settings['events']:
x_offset = 5
if event['importance'] == -1:
imp_img = Image.open('logos/low_imp.png')
elif event['importance'] == 0:
imp_img = Image.open('logos/med_imp.png')
elif event['importance'] == 1:
imp_img = Image.open('logos/high_imp.png')
if event['period'] != "":
clock_img = Image.open('logos/period.png')
period_img = self.textImage(event['period'].upper(), small_font, r=255, g= 85, b =0)
else:
clock_img = None
period_img = None
flag_img = Image.open('logos/economic_logos/' + event['country'] + '.png')
width, height = flag_img.size
flag_img = flag_img.resize((int(width/2), int(height/2)))
circle_img = Image.open('logos/indicator.png')
title_img = self.textImage((event['title'].upper()).replace("(", '').replace(")", ''), font, r = 255, g = 255, b = 255)
country_img = self.textImage(event['country'].upper(), small_font, r= 255, g = 255, b = 0)
date_img = self.textImage(event['time'].split(' ')[2], small_font, r=0, g=150, b=255)
indicator_img = self.textImage(event['indicator'], small_font, r=255, g=255, b=255)
if event['forecast'] != None or event['previous'] != None or event['actual'] != None:
try:
if event['forecast'] != None:
fore_img = self.textImage('Forecast', small_font, r=255,g=255,b=255)
fore2_img = self.textImage(str(event['forecast']), small_font, r=0, g=255, b=0)
if event['previous'] != None:
prev_img = self.textImage('Prior', small_font, r=255,g=255,b=255)
prev2_img = self.textImage(str(event['previous']), small_font, r=0, g=255, b=0)
actual_img = self.textImage('Actual', small_font, r=255,g=255,b=255)
if event['actual'] == None:
actual2_img = self.textImage('Soon', small_font, r=255, g=40, b=40)
else:
actual2_img = self.textImage(str(event['actual']), small_font, r=0, g=255, b=0)
except:
pass
x_off1 = x_offset + flag_img.size[0] + 2 + title_img.size[0] + 2 + country_img.size[0] + imp_img.size[0] + 2
x_off2 = x_offset + flag_img.size[0] + 2 + circle_img.size[0] + 2 + indicator_img.size[0] + 2 + date_img.size[0] + 2
try:
x_off2 += clock_img.size[0] + 2 + period_img.size[0] + 2
except:
pass
x_off3 = max(x_off1, x_off2)
try:
if event['forecast'] != None:
x_off3 += max(fore_img.size[0], fore2_img.size[0]) + 2
except:
pass
try:
if event['previous'] != None:
x_off3 += max(prev_img.size[0], prev2_img.size[0]) + 2
x_off3 += max(actual_img.size[0], actual2_img.size[0]) + 2
except:
pass
img = Image.new('RGB', (x_off3 + 5,16))
img.paste(flag_img, (x_offset, 0))
x_offset += flag_img.size[0] + 2
x_offset2 = x_offset
img.paste(title_img, (x_offset, 0))
x_offset += title_img.size[0] +2
img.paste(country_img, (x_offset, 2))
x_offset += country_img.size[0]
img.paste(imp_img, (x_offset, 1))
x_offset += imp_img.size[0] + 2
img.paste(circle_img, (x_offset2, 9))
x_offset2 += circle_img.size[0] + 2
img.paste(indicator_img, (x_offset2, 9))
x_offset2 += indicator_img.size[0] + 2
img.paste(date_img, (x_offset2, 9))
x_offset2 += date_img.size[0] + 2
try:
img.paste(clock_img, (x_offset2, 8))
x_offset2 += clock_img.size[0] + 2
img.paste(period_img, (x_offset2, 9))
x_offset2 += period_img.size[0] + 2
except:
pass
x_offset3 = max(x_offset, x_offset2)
try:
if event['forecast'] != None:
img.paste(fore_img, (x_offset3, 3))
img.paste(fore2_img, (x_offset3, 9))
x_offset3 += max(fore_img.size[0], fore2_img.size[0]) + 2
except:
pass
try:
if event['previous'] != None:
img.paste(prev_img, (x_offset3, 3))
img.paste(prev2_img, (x_offset3, 9))
x_offset3 += max(prev_img.size[0], prev2_img.size[0]) + 2
img.paste(actual_img, (x_offset3, 3))
img.paste(actual2_img, (x_offset3, 9))
x_offset3 += max(actual_img.size[0], actual2_img.size[0]) + 2
except:
pass
image_list.append(img)
except:
time.sleep(0.1)
no_econ = self.textImage('No upcoming economic events today.', font, r = 255, g = 255, b = 255)
img = Image.new('RGB', (no_econ.size[0] + 15, 16))
img.paste(no_econ, (10, 1))
image_list.append(img)
elif len(econ_settings['events']) == 0:
time.sleep(0.1)
no_econ = self.textImage('No upcoming economic events today.', font, r = 255, g = 255, b = 255)
img = Image.new('RGB', (no_econ.size[0] + 15, 16))
img.paste(no_econ, (10, 1))
image_list.append(img)
return self.stitchImage(image_list)
def ip_viewer(self):
@ -6013,6 +6149,8 @@ class StockTicker():
x_offset += images.size[0]
news.paste(ipo, (x_offset, 16))
x_offset += ipo.size[0]
news.paste(economic, (x_offset, 16))
x_offset += economic.size[0]
self.double_buffer = self.matrix.CreateFrameCanvas()
while True:
kill = stock_ticker.scrollImage(news, offset_x = 128)