mirror of
https://gitlab.com/triple-hops-brewed/raspberry-pi-stock-ticker.git
synced 2025-06-15 14:56:38 +00:00
final build ready for testing on Pi
This commit is contained in:
parent
621474ca43
commit
9a326d8918
BIN
requirements.txt
Normal file
BIN
requirements.txt
Normal file
Binary file not shown.
60
stock.py
60
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user