The following Python code could be used to display the titles of an RSS feed on an OLED display, attached to a Raspberry Pi.
You need to install the Python “feedparser” package:
sudo apt-get install feedparser
Don’t forget to adjust the OLED wiring values in the “OLED initialization” part.
Then, call the script with two parameters:
./feed.py http://www.yourfeed.com/rss 10
where the first parameter is the URL to the RSS feed and the second one is the number of seconds after a new title will be displayed on the OLED.
And here is the whole script:
#!/usr/bin/python import feedparser import time import sys import RPi.GPIO as GPIO, time, os import Adafruit_GPIO.SPI as SPI import Adafruit_SSD1306 from PIL import Image from PIL import ImageDraw from PIL import ImageFont # --- Parameters: feedUrl = sys.argv[1] interval = sys.argv[2] print "Feed: ", feedUrl print "interval: ", interval # --- OLED initialization: RST = None DC = 23 SPI_PORT = 0 SPI_DEVICE = 0 disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST) disp.begin() disp.clear() disp.display() def writeToDisplay(text): disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST) disp.begin() disp.clear() disp.display() width = disp.width height = disp.height image = Image.new('1', (width, height)) draw = ImageDraw.Draw(image) draw.rectangle((0,0,width,height), outline=0, fill=0) padding = -2 top = padding bottom = height-padding x = 0 font = ImageFont.load_default() temp = "" counter = 0 top = 0 for c in text: counter = counter + 1 temp = temp + c if counter % 20 == 0: draw.text((x, top), temp, font=font, fill=255) temp = "" top = top + 8 disp.image(image) disp.display() ########## Main ############ feedFeed = feedparser.parse(feedUrl) for item in feedFeed["items"]: writeToDisplay(item["title"]) print item["title"] time.sleep(float(interval))