try except to prevent crash when no portfolio_settings,json file
This commit is contained in:
parent
bf6a515b17
commit
e68401eb51
149
stockTicker.py
149
stockTicker.py
@ -1719,95 +1719,100 @@ class StockTicker():
|
|||||||
stitchedStock = midFrame
|
stitchedStock = midFrame
|
||||||
else:
|
else:
|
||||||
stitchedStock = midFrame
|
stitchedStock = midFrame
|
||||||
|
|
||||||
|
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']
|
||||||
|
shares = portfolio_settings[symbol]['shares']
|
||||||
|
|
||||||
if all_stocks_settings['chart'] and (symbol in portfolio_settings): #IF USER INPUTTED PORTFOLIO SETTINGS, DISPLAY PORTFOLIO INFO
|
original_value = float(cost) * float(shares)
|
||||||
try:
|
new_value = float(info['current']) * float(shares)
|
||||||
cost = portfolio_settings[symbol]['cost']
|
value_day_change_percent = ((float(info['percent_change'])/100) * new_value)
|
||||||
day = portfolio_settings[symbol]['day']
|
|
||||||
shares = portfolio_settings[symbol]['shares']
|
|
||||||
|
|
||||||
original_value = float(cost) * float(shares)
|
font = ImageFont.load("./fonts/5x8.pil")
|
||||||
new_value = float(info['current']) * float(shares)
|
cost_img = self.textImage('Cost', font, r = 255, g = 255 , b = 255)
|
||||||
value_day_change_percent = ((float(info['percent_change'])/100) * new_value)
|
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)
|
||||||
|
|
||||||
font = ImageFont.load("./fonts/5x8.pil")
|
pnlchange = new_value - original_value
|
||||||
cost_img = self.textImage('Cost', font, r = 255, g = 255 , b = 255)
|
pnlpercent = ((new_value - original_value) / original_value) * 100
|
||||||
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_img = self.textImage('P/L%', font, r = 255, g = 255 , b = 255)
|
||||||
pnlpercent = ((new_value - original_value) / original_value) * 100
|
if pnlpercent >= 0:
|
||||||
|
pnlpercent2_img = self.textImage(str('%.2f' % abs(pnlpercent)) + '%', font, r = 0, g = 255, b = 0)
|
||||||
pnlpercent_img = self.textImage('P/L%', font, r = 255, g = 255 , b = 255)
|
else:
|
||||||
if pnlpercent >= 0:
|
pnlpercent2_img = self.textImage(str('%.2f' % abs(pnlpercent)) + '%', font, r = 255, g = 0, b = 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)
|
daypercent_img = self.textImage('Day%', font, r = 255, g = 255 , b = 255)
|
||||||
if float(info['percent_change']) >= 0:
|
if float(info['percent_change']) >= 0:
|
||||||
daypercent2_img = self.textImage(str('%.2f' % abs(float(info['percent_change']))) +'%', font, r = 0, g = 255, b = 0)
|
daypercent2_img = self.textImage(str('%.2f' % abs(float(info['percent_change']))) +'%', font, r = 0, g = 255, b = 0)
|
||||||
else:
|
else:
|
||||||
daypercent2_img = self.textImage(str('%.2f' % abs(float(info['percent_change'])))+'%', font, r = 255, g = 0, b = 0)
|
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)
|
days_img = self.textImage('Days', font, r = 255, g = 255 , b = 255)
|
||||||
days2_img = self.textImage(day, font, r = 0, g = 255, b = 0)
|
days2_img = self.textImage(day, font, r = 0, g = 255, b = 0)
|
||||||
value_img = self.textImage('Value', font, r = 255, g = 255 , b = 255)
|
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)
|
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)
|
pnlchange_img = self.textImage('P/L$', font, r = 255, g = 255 , b = 255)
|
||||||
if pnlchange >= 0:
|
if pnlchange >= 0:
|
||||||
pnlchange2_img = self.textImage(str('%.2f' % abs(pnlchange)), font, r = 0, g = 255, b = 0)
|
pnlchange2_img = self.textImage(str('%.2f' % abs(pnlchange)), font, r = 0, g = 255, b = 0)
|
||||||
else:
|
else:
|
||||||
pnlchange2_img = self.textImage(str('%.2f' % abs(pnlchange)), font, r = 255, g = 0, b = 0)
|
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)
|
daychange_img = self.textImage('Day$', font, r = 255, g = 255 , b = 255)
|
||||||
if value_day_change_percent >= 0:
|
if value_day_change_percent >= 0:
|
||||||
daychange2_img = self.textImage(str('%.2f' % abs(value_day_change_percent)), font, r = 0, g = 255, b = 0)
|
daychange2_img = self.textImage(str('%.2f' % abs(value_day_change_percent)), font, r = 0, g = 255, b = 0)
|
||||||
else:
|
else:
|
||||||
daychange2_img = self.textImage(str('%.2f' % abs(value_day_change_percent)), font, r = 255, g = 0, b = 0)
|
daychange2_img = self.textImage(str('%.2f' % abs(value_day_change_percent)), font, r = 255, g = 0, b = 0)
|
||||||
|
|
||||||
x_offset = 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 +
|
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(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(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))
|
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(cost_img, (x_offset, 0))
|
||||||
img.paste(cost2_img, (x_offset, 8))
|
img.paste(cost2_img, (x_offset, 8))
|
||||||
img.paste(days_img, (x_offset, 16))
|
img.paste(days_img, (x_offset, 16))
|
||||||
img.paste(days2_img, (x_offset, 24))
|
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
|
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(shares_img, (x_offset, 0))
|
||||||
img.paste(shares2_img, (x_offset, 8))
|
img.paste(shares2_img, (x_offset, 8))
|
||||||
img.paste(value_img, (x_offset, 16))
|
img.paste(value_img, (x_offset, 16))
|
||||||
img.paste(value2_img, (x_offset, 24))
|
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
|
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(pnlpercent_img, (x_offset, 0))
|
||||||
img.paste(pnlpercent2_img, (x_offset, 8))
|
img.paste(pnlpercent2_img, (x_offset, 8))
|
||||||
img.paste(pnlchange_img, (x_offset, 16))
|
img.paste(pnlchange_img, (x_offset, 16))
|
||||||
img.paste(pnlchange2_img, (x_offset, 24))
|
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
|
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(daypercent_img, (x_offset, 0))
|
||||||
img.paste(daypercent2_img, (x_offset, 8))
|
img.paste(daypercent2_img, (x_offset, 8))
|
||||||
img.paste(daychange_img, (x_offset,16))
|
img.paste(daychange_img, (x_offset,16))
|
||||||
img.paste(daychange2_img, (x_offset, 24))
|
img.paste(daychange2_img, (x_offset, 24))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
image_list.append(stitchedStock)
|
image_list.append(stitchedStock)
|
||||||
if all_stocks_settings['chart'] and (symbol in portfolio_settings):
|
try:
|
||||||
try:
|
if all_stocks_settings['chart'] and (symbol in portfolio_settings):
|
||||||
image_list.append(img)
|
try:
|
||||||
except:
|
image_list.append(img)
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
pass
|
||||||
image_list.append(self.blank)
|
image_list.append(self.blank)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user