Last active
June 23, 2022 10:35
-
-
Save Simon-Ince/5beb5e059d855583a75f2b6e588113b5 to your computer and use it in GitHub Desktop.
Show Twitter feed on and LED matrix using the hzeller/rpi-rgb-led-matrix Python library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from samplebase | |
import SampleBase | |
from rgbmatrix | |
import graphics | |
import time | |
import twitter | |
api = twitter.Api(consumer_key = '???', | |
consumer_secret = '???', | |
access_token_key = '???', | |
access_token_secret = '???') | |
t = api.GetUserTimeline(screen_name = "jackatlush", count = 1) | |
tweets = [i.AsDict() for i in t] | |
for t in tweets: | |
print(t['text']) | |
class RunText(SampleBase): | |
def __init__(self, * args, ** kwargs): | |
super(RunText, self).__init__( * args, ** kwargs) | |
self.parser.add_argument("-t", "--text", help = "The text to scroll on the RGB LED panel", | |
default = "Hello world!") | |
def run(self): | |
offscreen_canvas = self.matrix.CreateFrameCanvas() | |
font = graphics.Font() | |
font.LoadFont("../../../fonts/10x20.bdf") | |
textColor = graphics.Color(255, 0, 255) | |
pos = offscreen_canvas.width | |
while True: | |
global tweets | |
offscreen_canvas.Clear() | |
len = graphics.DrawText(offscreen_canvas, font, pos, 15, textColor, tweets[0]['text']) | |
pos -= 2 | |
if (pos + len < 0): | |
pos = offscreen_canvas.width | |
t = api.GetUserTimeline(screen_name = "jackatlush", count = 1) | |
tweets = [i.AsDict() for i in t] | |
for t in tweets: | |
print(t['text']) | |
time.sleep(0.05) | |
offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas) | |
# Main | |
function | |
if __name__ == "__main__": | |
run_text = RunText() | |
if (not run_text.process()): | |
run_text.print_help() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment