A simple Python feedparser script

As a quick example today, the following source code is for a Python feedparser script I wrote, based on the URL shown:

#!/usr/bin/python

#
# from http://www.pythonforbeginners.com/feedparser/using-feedparser-in-python
# installed feedparser with `pip`, after installing pip with apt-get
#

import feedparser
import time
from subprocess import check_output

# ------
# uptime
# ------

uptime = check_output(['uptime'])
print "\n"
print '-------------------------------------------------------------'
print uptime.strip()
print '-------------------------------------------------------------'
print "\n"


# --------------------
# tribune (feedparser)
# --------------------

d = feedparser.parse('http://chicagotribune.feedsportal.com/c/34253/f/622872/index.rss')

# print all posts
count = 1
blockcount = 1
for post in d.entries:
    if count % 5 == 1:
        print "\n" + time.strftime("%a, %b %d %I:%M %p") + '  ((( TRIBUNE - ' + str(blockcount) + ' )))'
        print "-----------------------------------------\n"
        blockcount += 1
    print post.title + "\n"
    count += 1

In addition to showing how to use feedparser, the script also shows how to run system command in Python, and also how to get and format the time with Python.

Output

At the current moment (May 27, 2014), this script produces the following output:

-------------------------------------------------------------
14:38:28 up 23:16,  2 users,  load average: 1.60, 0.93, 0.56
-------------------------------------------------------------

Tue, May 27 02:38 PM  ((( TRIBUNE - 1 )))
-----------------------------------------

Bears DE Allen revitalized by change of scenery

Dolphins' Pouncey: No need for psychological testing

Heat's Birdman travels for Game 5, status uncertain

Bears playing Jennings at slot CB

Heat looking to take the fifth, silence the Pacers


Tue, May 27 02:38 PM  ((( TRIBUNE - 2 )))
-----------------------------------------

Cubs unveil new drawings, expanded underground clubhouse

Rangers' Stepan skates with broken jaw

Wozniacki loses on return after broken engagement

Two sprinters in Jamaican drug scandal appeal their suspensions

Kromer, Meyer to oversee Bears' O-line

Screensaver

I use this script output with a text-based screensaver on my “AlRadio” project, which is a Raspberry Pi radio. I write this output to a file every few minutes, then read that file with the _Phosphor_ screensaver, which is one of the available =xscreensaver= utilities.