From 0dd2718793bda11157e108919520281d920e96f9 Mon Sep 17 00:00:00 2001 From: Roberto DeFeo Date: Tue, 18 May 2021 11:38:34 -0400 Subject: [PATCH] Fixed divide by zero error #5 --- stonks.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stonks.py b/stonks.py index ca040ee..ca1651a 100644 --- a/stonks.py +++ b/stonks.py @@ -38,7 +38,6 @@ def render(self): tickerData = yf.Ticker(ticker).info except: debug.error(f"Unable to fetch data for {ticker}") - quit() continue last_price = tickerData["regularMarketPrice"] @@ -54,7 +53,6 @@ def render(self): cd = yf.download(tickers=ticker,interval="1m",period="1d",progress=False) except: debug.error(f"Unable to fetch intraday tick data for {ticker}") - quit() continue prices = cd["Close"].tolist() @@ -66,15 +64,20 @@ def render(self): prevcl_Y = LED_HEIGHT-1 elif prev_close > maxp: prevcl_Y = CHART_Y + elif maxp == minp: + prevcl_Y = CHART_Y else: prevcl_Y = int(CHART_Y + (maxp-prev_close)*((LED_HEIGHT-CHART_Y)/(maxp-minp))) # debug.info(f"{ticker} prev close {prevcl_Y}") for x in range(LED_WIDTH): p = prices[int(x * x_inc)] # Get the subsampled price, based on our X Axis position - y = int(CHART_Y + (maxp-p)*((LED_HEIGHT-CHART_Y)/(maxp-minp))) # compute Y value + if maxp == minp: + y = CHART_Y + else: + y = int(CHART_Y + (maxp-p)*((LED_HEIGHT-CHART_Y)/(maxp-minp))) # compute Y value color = GREEN if p > prev_close else RED step = -1 if y > prevcl_Y else 1 # compute up/down direction for chart area fill - for ys in range(y,prevcl_Y,step): # draw area fill + for ys in range(y,prevcl_Y+step,step): # draw area fill dim_y = y/ys if step == 1 else ys/y # dimmer color near prev close self.matrix.draw_pixel((x,ys-1),tuple([int(i * 0.25 * dim_y) for i in color])) self.matrix.draw_pixel((x,y-1),color) # finally, draw the price values @@ -101,4 +104,4 @@ def render(self): self.matrix.render() self.sleepEvent.wait(self.data.config.stonks_rotation_rate) self.matrix.clear() - # debug.info("done wit sToNkS!") \ No newline at end of file + # debug.info("done wit sToNkS!")