Rssparse.py needs some help

I am trying to modify this nice news feed code from https://gist.github.com/chubbyemu/4ca0c68878c6d978d067da4a36bcc71d

I got it to partially work using ‘demo’, albeit it is not automatically changing news feeds. Curiously, it will change feeds if I invoke Ctrl-C. So I don’t know how to fix this just yet. I am using 3 horizontally chained 16x32 panels. I am also still using python 2.7.16 with the following changes:

  1. Changed line 51 from ‘unicode’ to ‘str’.
  2. Changed line 70 ‘16’ to ‘10’ to resize font to a smaller size. I also changed the font type here to DejaVuSerif.ttf.
  3. Changed line 96 to os.system("sudo ./demo -D 1 --led-cols=96 --led-rows=16 --led-brightness=75 --led-chain=3 "+disp)
  4. Invoking code from /home/pi/rpi-rgb-led-matrix/examples-api-use

Lingering issues:

  1. Feed doesn’t automatically update.
  2. Scroll speed too fast
  3. Sometimes on start it fails and have to re-start.

I will try to figure it out using runtext. This did not work:
os.system("sudo ./runtext.py --led-cols 96 -r 16 -b 50 -c 3 --text"+disp)

coming over from github - my biggest challenge right now is that I can’t get it to work without having to keep pressing control+c to get it to switch stories!

I am going to start modifying this for python3

yeah that’s what I did - obviously summarized all my changes in the comments - so far got it all the way where I want it just except the fact that I have to press control c to change the stories lol

What about the thought about addidng some timer related interruption which do the same that CTRL+C does > changing rssfeed, which is actually a picture maybe like after 60 seconds.

I think the -t 60 in rssparse.py end leads somewhere to older versions on demo-main and not in rssparse.py.
So instead of rssparse.py, the code in demo-main should be modified. There’s some changes in the last 2-3 years instead of rssparse.py, where’s pretty much nothing modifications.

My ”coding skills” are blank paper, can program only lathe. :roll_eyes:

But just a thought for more experienced coders.

Should be os.system("sudo ./scrolling-text-example -f ../fonts/5x8.bdf -y3 -l1 -$”+disp)

Thats how I got it working.

Thanks for code by the way.

No it doesn’t change colour, but there’s space between messages. I changed the repetition from one to two.

It seems it stops working after a while, 30-45minutes, maybe not getting new RSS feeds.

Somehow it started again after like two hours pause. :blush:

Try my version, it will change color.

I am experimenting with sending non-alphanumeric unicode characters through, but only the “hearts” display properly. Anyone have a clue how to translate them into the display?

Reference: ✔️ ❤️ ★ Unicode Character Table

I copied all your code, just had to modify it for my setup, which is same which chubbyemu uses on his video. But it didn’t changed colour.

Not sure why. Did you install the other library? Also, the color def() are remnants that can be deleted. I tried to delete in above code but it’s not letting me.

I use this newest rpi-rgb-led-matrix.
Colour is yellowish, but before, when it changed colours, colours were red, green and blue.

The code I uploaded had some indent errors which I fixed. Perhaps it will work now. I find when I cut and paste code here sometimes it isn’t indented correctly.

1 Like

For disp in titles - I had to remove spaces, so it starts from first vertical line. It gave some indent error.

But now it gives message News fetched at…

Will get more News next half hour.

But display stay dark and nothing else happens on raspberry terminal.

I tried that older version, which showed yellow text, there it left always first word out of feed.

Thanks again.

Unfortunately I cannot figure out how to paste the working code with proper indents. I will check with the admin.

Try this and see. The indents seem ok.

# THIS SCRIPT USES THE LIBRARY AT:

# https://github.com/hzeller/rpi-rgb-led-matrix

# BE SURE TO CLONE IT AND READ THE README, as highlighted in the video :)

import os, time, threading, random

import feedparser

from PIL import Image, ImageFont, ImageDraw

from random import shuffle, choice

BITLY_ACCESS_TOKEN="BITLY_ACCESS_TOKEN"

items=[]

titles=[]

displayItems=[]

feeds=[

    #enter all news feeds you want here

    "https://www.spglobal.com/spdji/en/rss/rss-details/?rssFeedName=corporate-news",

    "https://markets.businessinsider.com/rss/news",

    "https://markets.businessinsider.com/rss/analysts-opinions",

    "https://www.globenewswire.com/RssFeed/orgclass/1/feedTitle/GlobeNewswire%20-%20News%20about%20Public%20Companies",

    "https://www.globenewswire.com/RssFeed/subjectcode/13-Earnings%20Releases%20And%20Operating%20Results/feedTitle/GlobeNewswire%20-%20Earnings%20Releases%20And%20Operating%20Results",

    "https://www.globenewswire.com/RssFeed/subjectcode/8-Calendar%20Of%20Events/feedTitle/GlobeNewswire%20-%20Calendar%20Of%20Events",

    "https://www.globenewswire.com/RssFeed/subjectcode/43-Technical%20Analysis/feedTitle/GlobeNewswire%20-%20Technical%20Analysis",

    "https://seekingalpha.com/market_currents.xml",

    "https://www.investing.com/rss/news.rss",

    "https://stocksnewsfeed.com/feed/",

    "https://feeds.a.dj.com/rss/RSSWorldNews.xml",

    "https://feeds.a.dj.com/rss/RSSWSJD.xml",

    "https://feeds.a.dj.com/rss/WSJcomUSBusiness.xml",

    "http://www.cnbc.com/id/19746125/device/rss/rss.xml",

    ]

def populateItems():

    #first clear out everything

    del items[:]

    del displayItems[:]

    #delete all the image files

    os.system("find . -name \*.ppm -delete")

    for url in feeds:

        feed=feedparser.parse(url)

        posts=feed["items"]

        for post in posts:

            items.append(post)

    shuffle(items)

def createLinks():

    try:

        populateItems()

        for idx, item in enumerate(items):

            title = item["title"].encode('ascii', 'ignore').decode()

            titles.append(title)

    except ValueError:

        print("Bummer :( I couldn't make you 'dem links :(")

    finally:

        print("\nWill get more news next half hour!\n\n")

def run():

    print("News Fetched at {}\n".format(time.ctime()))

    createLinks()

    threading.Timer(len(items) * 60, run).start()

    showOnLEDDisplay()

def showOnLEDDisplay():

    #for disp in displayItems[:60]:

    

   colors = [

    "255,0,0",    # red

    "0,255,0",    # green

    "189,51,164", # byzantinee

    "252,194,0"   # golden poppy

   ]

   for disp in titles:

        print(disp) 

        randomColor = choice(colors)

        title = "'" + disp + "'"

        os.system("sudo ./scrolling-text-example -f ../fonts/5x8.bdf -y3 -s9  -l1 -C "+ randomColor +"  -B 0,48,143 --led-cols=96 --led-rows=16  --led-brightness=50 --led-chain=3 "+title)

if __name__ == '__main__':

    run()
1 Like

Now it seems to work ok and it stays on now, when earlier it stopped working. Thank you jax2000.

Backround colour is cool, but I turned it off, so it doesn’t use so much power. I just thought that if it would cause problems, but I’m a pessimist. :rofl:

Edit. After posting message, display stopped. But now I added more feeds, so I hope it would stay on longer.

Good to hear it is good code. :sweat_smile:

It is a starting point and of course it can be modified as you wish. I am using a 5v, 4a power supply and so far no issues. Yes, it stops after awhile and can be modified to loop. I am also going to modify it to start with the power button, so I don’t have to ssh into it each time.

I find it a fun platform to work with and develop other interesting projects (I’ll post).

Now it works pretty long as I have many feeds, but eventually it pauses for a long time. I left mine on and at some time when I was in sleep, it started again.

Just wondering, what code or something is doing that update. Could it update sooner, so no long pause?