scrolling text implimented in Python
This commit is contained in:
parent
992251955d
commit
799fd16f8f
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "rpi-rgb-led-matrix"]
|
||||||
|
path = rpi-rgb-led-matrix
|
||||||
|
url = https://github.com/hzeller/rpi-rgb-led-matrix/
|
Binary file not shown.
1
rpi-rgb-led-matrix
Submodule
1
rpi-rgb-led-matrix
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit dfc27c15c224a92496034a39512a274744879e86
|
@ -13,12 +13,15 @@ from PIL import Image, ImageDraw, ImageFont
|
|||||||
import time
|
import time
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
||||||
|
|
||||||
|
|
||||||
class StockTicker():
|
class StockTicker():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#Define global resources
|
#Define global resources
|
||||||
self.symbols = []
|
self.symbols = []
|
||||||
self.ApiKeys = [["b1be6696d54342bdb5c8f59a052854fd","237d183faf984e7eba708a647c55153a","3012b3cb19784ed4be2b02e9907e53cb"],["f835e85df2a74df1904fe6dc53bcc17a","41ec268496744c34a96e3c408081300b","2d566fc71ade46d688713b13730c5219"]]
|
#self.ApiKeys = [["b1be6696d54342bdb5c8f59a052854fd","237d183faf984e7eba708a647c55153a","3012b3cb19784ed4be2b02e9907e53cb"],["f835e85df2a74df1904fe6dc53bcc17a","41ec268496744c34a96e3c408081300b","2d566fc71ade46d688713b13730c5219"]]
|
||||||
#self.ApiKeys = [["6172b84d1f464ad88b95ed52e4391bce","979f9b8c9ee748fbbb57cb490ccaaf42","593fa818a44144699b75433aafd92d15"]
|
self.ApiKeys = [["6172b84d1f464ad88b95ed52e4391bce","979f9b8c9ee748fbbb57cb490ccaaf42","593fa818a44144699b75433aafd92d15"]]
|
||||||
self.retrievedList = []
|
self.retrievedList = []
|
||||||
self.greenORred = (255, 255, 255)
|
self.greenORred = (255, 255, 255)
|
||||||
self.ListStocks = []
|
self.ListStocks = []
|
||||||
@ -31,6 +34,63 @@ class StockTicker():
|
|||||||
self.Delay = 20
|
self.Delay = 20
|
||||||
self.parseCSV = 0
|
self.parseCSV = 0
|
||||||
self.symbolLength = 0
|
self.symbolLength = 0
|
||||||
|
self.brightness = 1.0
|
||||||
|
|
||||||
|
# Configuration for the matrix
|
||||||
|
options = RGBMatrixOptions()
|
||||||
|
options.rows = 64
|
||||||
|
options.cols = 64
|
||||||
|
options.chain_length = 1
|
||||||
|
options.parallel = 1
|
||||||
|
options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat'
|
||||||
|
options.gpio_slowdown = 4
|
||||||
|
self.matrix = RGBMatrix(options = options)
|
||||||
|
|
||||||
|
def openImage(self, image_file):
|
||||||
|
image = Image.open(image_file)
|
||||||
|
# Make image fit our screen.
|
||||||
|
#image.thumbnail((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
|
||||||
|
|
||||||
|
image = image.convert('RGB')
|
||||||
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
def SetImage(self, image, pos_x = 0, pos_y = 0, offset_x = 0, offset_y = 0, unsafe=True):
|
||||||
|
|
||||||
|
|
||||||
|
if (image.mode != "RGB"):
|
||||||
|
raise Exception("Currently, only RGB mode is supported for SetImage(). Please create images with mode 'RGB' or convert first with image = image.convert('RGB'). Pull requests to support more modes natively are also welcome :)")
|
||||||
|
|
||||||
|
if unsafe:
|
||||||
|
#In unsafe mode we directly access the underlying PIL image array
|
||||||
|
#in cython, which is considered unsafe pointer accecss,
|
||||||
|
#however it's super fast and seems to work fine
|
||||||
|
#https://groups.google.com/forum/#!topic/cython-users/Dc1ft5W6KM4
|
||||||
|
img_width, img_height = image.size
|
||||||
|
self.matrix.SetPixelsPillow(offset_x, offset_y, img_width, img_height, image)
|
||||||
|
else:
|
||||||
|
# First implementation of a SetImage(). OPTIMIZE_ME: A more native
|
||||||
|
# implementation that directly reads the buffer and calls the underlying
|
||||||
|
# C functions can certainly be faster.
|
||||||
|
img_width, img_height = image.size
|
||||||
|
pixels = image.load()
|
||||||
|
for x in range(max(0, -offset_x), min(img_width, self.matrix.width - offset_x)):
|
||||||
|
for y in range(max(0, -offset_y), min(img_height, self.matrix.height - offset_y)):
|
||||||
|
(r, g, b) = pixels[x, y]
|
||||||
|
|
||||||
|
self.matrix.SetPixel(x + offset_x, y + offset_y, r*brightness, g*brightness, b*brightness)
|
||||||
|
|
||||||
|
|
||||||
|
def ScrollImage(self, image_file, pos_x = 0, pos_y = 0, delay = 0.05):
|
||||||
|
image = self.openImage(image_file)
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
self.SetImage(image, offset_x = -i, offset_y = 0)
|
||||||
|
time.sleep(delay)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Get the logo from file that is the same as ticker name
|
#Get the logo from file that is the same as ticker name
|
||||||
def getLogo(self, Ticker):
|
def getLogo(self, Ticker):
|
||||||
@ -72,7 +132,7 @@ class StockTicker():
|
|||||||
|
|
||||||
#Draw Ticker, current and change onto one image
|
#Draw Ticker, current and change onto one image
|
||||||
def textToImage(self, TICKER, CURRENT, CHANGE, ARROW):
|
def textToImage(self, TICKER, CURRENT, CHANGE, ARROW):
|
||||||
font = ImageFont.truetype("EncodeSans.ttf", 18)
|
font = ImageFont.load("7x14.pil")
|
||||||
img = Image.new('RGB', (150, 32))
|
img = Image.new('RGB', (150, 32))
|
||||||
d = ImageDraw.Draw(img)
|
d = ImageDraw.Draw(img)
|
||||||
|
|
||||||
@ -110,7 +170,7 @@ class StockTicker():
|
|||||||
|
|
||||||
#Get current prices and day prices for the ticker then format the response into an array
|
#Get current prices and day prices for the ticker then format the response into an array
|
||||||
def getStockPrices(self, APIKEY, SYMBOLS):
|
def getStockPrices(self, APIKEY, SYMBOLS):
|
||||||
|
APIKEY = "237d183faf984e7eba708a647c55153a"
|
||||||
try:
|
try:
|
||||||
symbols_list = SYMBOLS.split(",")
|
symbols_list = SYMBOLS.split(",")
|
||||||
td = TDClient(apikey=APIKEY)
|
td = TDClient(apikey=APIKEY)
|
||||||
@ -141,7 +201,7 @@ class StockTicker():
|
|||||||
j=0
|
j=0
|
||||||
while (j<3):
|
while (j<3):
|
||||||
print('API KEY: ' + str(self.ApiKeys[self.keySwapper][j]))
|
print('API KEY: ' + str(self.ApiKeys[self.keySwapper][j]))
|
||||||
|
# NT: this weird API key thing doesnt work, when I hard code the API key in the above function it does
|
||||||
self.getStockPrices(self.ApiKeys[self.keySwapper][j], self.symbols[(j+self.parseCSV)][0])
|
self.getStockPrices(self.ApiKeys[self.keySwapper][j], self.symbols[(j+self.parseCSV)][0])
|
||||||
|
|
||||||
if (self.ApiCalledError == False):
|
if (self.ApiCalledError == False):
|
||||||
|
BIN
stockTicker.pyc
BIN
stockTicker.pyc
Binary file not shown.
18
test.py
Normal file
18
test.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from twelvedata import TDClient
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import threading
|
||||||
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
import time
|
||||||
|
import csv
|
||||||
|
|
||||||
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
||||||
|
from stockTicker import StockTicker
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
stock_ticker = StockTicker()
|
||||||
|
|
||||||
|
while(True):
|
||||||
|
stock_ticker.ScrollImage('final.ppm')
|
||||||
|
time.sleep(100)
|
Loading…
Reference in New Issue
Block a user