# Display a runtext with double-buffering. from rgbmatrix import graphics, RGBMatrix, RGBMatrixOptions import time import sys import requests options = RGBMatrixOptions() options.rows = 16 options.cols = 32 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = "regular" def symbolData(symbol: str): """ Takes a list of symbol and returns a dictionary of strings with information about the symbol. """ IEX_TOKEN = "TOKEN HERE" IEXurl = "https://cloud.iexapis.com/stable/stock/{symbol}/quote?token={IEX}".format( symbol=symbol, IEX=IEX_TOKEN ) response = requests.get(IEXurl) if response.status_code is 200: IEXData = response.json() message = "The current stock price of {name} is $**{price}**".format( name=IEXData["companyName"], price=IEXData["latestPrice"] ) # Determine wording of change text change = round(IEXData["changePercent"] * 100, 2) if change > 0: message += ", the stock is currently **up {change}%**".format(change=change) elif change < 0: message += ", the stock is currently **down {change}%**".format( change=change ) else: message += ", the stock hasn't shown any movement today." else: message = "The symbol: {symbol} was not found.".format(symbol=symbol) return message def run(): matrix = RGBMatrix(options=options) offscreen_canvas = matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("../../../fonts/7x13.bdf") textColor = graphics.Color(255, 255, 0) pos = offscreen_canvas.width my_text = "loading" while True: offscreen_canvas.Clear() len = graphics.DrawText(offscreen_canvas, font, pos, 10, textColor, my_text) pos -= 1 if pos + len < 0: my_text = symbolData("tsla") pos = offscreen_canvas.width time.sleep(0.05) offscreen_canvas = matrix.SwapOnVSync(offscreen_canvas) try: print("Press CTRL-C to stop.") while True: run() except KeyboardInterrupt: sys.exit(0)