diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..86dd31f Binary files /dev/null and b/requirements.txt differ diff --git a/stock.py b/stock.py index 0e80256..8e0765f 100644 --- a/stock.py +++ b/stock.py @@ -5,15 +5,14 @@ from math import ceil import numpy as np import requests from bdfparse import Font + from keys import IEX_TOKEN - from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics - font_file = "matrix\\fonts\\9x15.bdf" font = Font(font_file) matrix_shape = (16, 32) # rows, cols -stocks = ["tsla", "psec", "aapl"] +symbols = ["tsla", "psec", "aapl"] options = RGBMatrixOptions() @@ -72,31 +71,6 @@ def symbolData(symbol: str): return (message, color) -def run(pos): - matrix = RGBMatrix(options=options) - canvas = matrix.CreateFrameCanvas() - - for row in range(options.rows): - for col in range(options.cols): - canvas.SetPixel(x, y, 255, 1, 1) - - canvas = matrix.SwapOnVSync(canvas) - time.sleep(1) - - -try: - print("Press CTRL-C to stop.") - pos = 0 - matrix = stockMatrix(symbols) - while True: - run(pos) - pos += 1 - - -except KeyboardInterrupt: - sys.exit(0) - - def matrix_message(message, color, rows): message_arr = fit_array(font.word(message), rows) @@ -136,3 +110,33 @@ def fit_array(array, rows, operation="centered", fill_value=0): else: raise Exception("Invalid Operation. Must be either centered, top, or bottom.") + +def run(matrix_message): + matrix = RGBMatrix(options=options) + canvas = matrix.CreateFrameCanvas() + + for row in range(matrix_shape[0]): + for col in range(matrix_shape[1]): + r = matrix_message[row, col, 0] + g = matrix_message[row, col, 1] + b = matrix_message[row, col, 2] + canvas.SetPixel(row, col, r, g, b) + + canvas = matrix.SwapOnVSync(canvas) + time.sleep(1) + + +try: + print("Press CTRL-C to stop.") + + matrix = stockMatrix(symbols) + while True: + run(matrix) + matrix = matrix[:, 1:, :] + if matrix.shape[1] < matrix_shape[1]: + new_matrix = stockMatrix(symbols) + matrix = np.concatenate((matrix, new_matrix), axis=1) + + +except KeyboardInterrupt: + sys.exit(0)