diff --git a/stockTicker.py b/stockTicker.py index ca417e2..ae8b660 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -1149,8 +1149,7 @@ class StockTicker(): def getCryptoProfessional(self): - - + self.blank = Image.new('RGB', (0, 16)) f = open('csv/crypto_settings.json', 'r') @@ -1163,15 +1162,18 @@ class StockTicker(): image_list.append(self.blank) else: image_list = [] - - + + if all_crypto_settings['chart']: + try: + f = open('csv/portfolio_crypto_settings.json', 'r') + portfolio_settings = json.load(f)['symbols'] + f.close() + except: + pass coin_info = all_crypto_settings['symbols'] coin_bases = list(coin_info.keys()) - - - for i, cb in enumerate(coin_bases): try: ticker, base = cb.split(',') @@ -1186,7 +1188,6 @@ class StockTicker(): # convert percent to points change = '%.2f' % abs(float(coin_info[cb]['percent_change'])) + '%' else: - change = str(changefinal) current = str(current_final) @@ -1204,21 +1205,110 @@ class StockTicker(): stitchedStock = midFrame else: stitchedStock = midFrame + + try: + if all_crypto_settings['chart'] and (cb in portfolio_settings): #IF USER INPUTTED PORTFOLIO SETTINGS, DISPLAY PORTFOLIO INFO + try: + cost = portfolio_settings[cb]['cost'] + day = portfolio_settings[cb]['day'] + shares = portfolio_settings[cb]['shares'] + + original_value = float(cost) * float(shares) + new_value = float(coin_info[cb]['current']) * float(shares) + value_day_change_percent = ((float(coin_info[cb]['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(coin_info[cb]['percent_change']) >= 0: + daypercent2_img = self.textImage(str('%.2f' % abs(float(coin_info[cb]['percent_change']))) +'%', font, r = 0, g = 255, b = 0) + else: + daypercent2_img = self.textImage(str('%.2f' % abs(float(coin_info[cb]['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_crypto_settings['chart'] and (cb in portfolio_settings): + try: + image_list.append(img) + except: + pass + except: + pass + image_list.append(self.blank) except Exception as e: pass -# logf = open('log.txt', "a") -# exc_type, exc_obj, exc_tb = sys.exc_info() -# fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] -# logf.write(str(e)) -# logf.write('. file: ' + fname) -# logf.write('. line: ' + str(exc_tb.tb_lineno)) -# logf.write('. type: ' + str(exc_type)) -# logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))) -# logf.close() finalDisplayImage = self.stitchImage(image_list) self.blank = Image.new('RGB', (10, 32))