mirror of
https://gitlab.com/triple-hops-brewed/raspberry-pi-stock-ticker.git
synced 2025-06-15 14:56:38 +00:00
first functional version of the stock ticker
This commit is contained in:
parent
8c119a910b
commit
2f0ec542cd
15
README.md
15
README.md
@ -1,2 +1,17 @@
|
||||
# Raspberry Pi Stock Ticker
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
Install dietpi normally
|
||||
|
||||
```bash
|
||||
git clone https://github.com/hzeller/rpi-rgb-led-matrix.git
|
||||
cd ./rpi-rgb-led-matrix/
|
||||
sudo apt-get update && sudo apt-get install python3-dev git pip build-essential -y
|
||||
make build-python PYTHON=python3
|
||||
sudo make install-python PYTHON=python3
|
||||
cd ./bindings/python/samples/
|
||||
wget https://gitlab.com/snippets/1874042/raw -O stock.py
|
||||
pip3 install requests==2.22.0
|
||||
sudo python3 ./stock.py
|
||||
```
|
||||
|
74
stock.py
Normal file
74
stock.py
Normal file
@ -0,0 +1,74 @@
|
||||
# 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user