Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: RSS news on the desktop with conky
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Nuteater
Apprentice
Apprentice


Joined: 25 Sep 2003
Posts: 193
Location: Jyväskylä, Finland

PostPosted: Sat Sep 24, 2005 2:01 pm    Post subject: HOWTO: RSS news on the desktop with conky Reply with quote

HOWTO: RSS news on the desktop with conky

Prologue

According to scientific studies (by me), having RSS news on your desktop will
improve your quality of life by 32-47% (proven by a test study of 1 people).
After following this guide, you should end up with something like this.
This guide is based on a post by Adrian Frei (Shai'tan) on the October
2004 Gentoo Desktops thread, and all credit belongs to him.

In this guide I assume you are already familiar with conky, the second coming
of the mean, lean system monitor torsmo. For information on how to install
or finetune conky, see other sources.

How it's done

First of all we need to parse the RSS sources and dump them as text for conky. For
this we use Adrian Frei's rssdisplay.py script. The original script is no longer accessible,
so I can only offer you a version slightly modified by me. The original script came with no
license description, but as it was posted on a public forum I'll assume redistribution and
modification are permitted.

For rssdisplay.py to work, you'll need Mark Nottingham's RSS module for python. To make
the module work, you'll need to apply a patch which fixes the location of sax.make_parser().
Place the patched RSS.py on your $PYTHONPATH, or in the same directory you will place
rssdisplay.py to. I have both in ~/bin, and in this guide I will assume you do as well.

Here is the rssdisplay.py script. Put it in ~/bin or whatever suits your needs, and chmod it +x.
You can also download it here.
Code:
#!/usr/bin/python

#Very simple newsfeed-display programm (e.g. to use in torsmo)
#You'll need Mark Nottinghams RSS.py in your $PYTHONPATH
#
#Adrian Frei <adrian[d]frei[a]freesurf[d]ch>

#Minor modifications by Perttu Luukko (Nuteater) <pejajulu(a)cc(d)jyu(d)fi>

from RSS import ns, CollectionChannel, TrackingChannel
import sys, csv, re

#Usage Message
def usage():
    sys.stdout.write( "Usage: ./pyrssdisplay configfile\n")

#Main program   
arg = sys.argv[1:]
if 0<len(arg)<2:
    try:
        config=[]
        configFile = csv.reader(file(arg[0]))
        #Get rid of the comments
        for row in configFile:
                if row[0][0] !='#':
                config.append(row)

        for row in config:
            #Create a tracking channel, which is a data structure that
            #Indexes RSS data by item URL
            tc = TrackingChannel()

            #Returns the RSSParser instance used, which can usually be ignored
            tc.parse(row[1])

            RSS10_TITLE = (ns.rss10, 'title')
            RSS10_DESC = (ns.rss10, 'description')

            items = tc.listItems()
            messagesToDisplay = int(row[2])
            for item in items:
                item_data = tc.getItem(item)
                tmp = item_data.get(RSS10_TITLE, "(none)")
                splitted = re.split("[ ]", tmp)
                totalLen = 50
                output = ""
                newLine = True
                for token in splitted:
                    totalLen = totalLen - len(token) -1
                    if totalLen < 0:
                        #sys.stdout.write(output.decode('utf-8').encode('latin-1')+"\n")
                        sys.stdout.write(output+"\n")
                        totalLen = 40 - len(token)
                        output = ""
                        newLine = True
                    if newLine:
                        output = output + token
                    else:
                        output = output + " " + token
                    newLine = False
                #sys.stdout.write(output.decode('utf-8').encode('latin-1')+"\n")
                sys.stdout.write(output+"\n")
                messagesToDisplay = messagesToDisplay - 1
                if messagesToDisplay <= 0:
                    break
    except ValueError, e:
        sys.stdout.write("Error: " +str(e))
        sys.exit()
    except IOError, e:
        sys.stdout.write("Error: " +str(e))
        sys.exit()

    sys.exit()
else:
    usage()
    sys.exit()

If you want the output to be in iso8859-1 instead of utf-8, change the
Code:
#sys.stdout.write(output.decode('utf-8').encode('latin-1')+"\n")
                sys.stdout.write(output+"\n")

to
Code:
sys.stdout.write(output.decode('utf-8').encode('latin-1')+"\n")
                #sys.stdout.write(output+"\n")


Next, create the config files for rssdisplay.py. The format of the config files is
Code:
topic,uri to RSS feed,number of items to display
For example:
Code:
GLSA,http://www.gentoo.org/rdf/en/glsa-index.rdf,4
We will use the config file filenames as the topic for the news list, so name them
accordingly. For example, I have the example config file saved as 'GLSA'.
Place the config files in a directory - in this guide I have used ~/.rssdisplay.
Now the command
Code:
~/bin/rssdisplay.py ~/.rssdisplay/GLSA
should output the 4 latest items on the GLSA newsfeed as plain old text.

Instead of running these scripts from conky, we'll dump the news to a text file
first and cat the text file from conky. To do that we use this script, which I call
update_rss.sh:
Code:
#!/bin/bash
echo -n "" > ~/.rss
cd ~/.rssdisplay/
for conf in ./*
do
    echo "$conf" | cut -d"/" -f 2 >> ~/.rss
    echo >> ~/.rss
    ~/bin/rssdisplay.py "$conf" >> ~/.rss
    echo >> ~/.rss
done

As you can see, this script dumps the news to ~/.rss, separating each feed by a header
and an empty line. Nice! Now we have a more or less ready news collection easily
accessible by powertools such as conky. To keep the news up to date (after testing that
update_rss.sh works) make it to execute periodically with your favourite cron tool
(Remember: Do not abuse the RSS feeds with too frequent queries - once
every 30min or so should suffice).

Okay, and now the final touch: making conky display the news. As the news are now in a plain
old text file, just add something like
Code:
${execi 20 cat ~/.rss}

to your .conkyrc. That's it! :) Can you feel the warm feeling RSS news on the desktop gives you?

Epilogue

This is the first draft of this howto, so it probably has plenty of errors and omissions. Attach your feedback below.
_________________
I am Nuteater, hear me roar.
Back to top
View user's profile Send private message
thewally
l33t
l33t


Joined: 12 May 2005
Posts: 703
Location: Genova

PostPosted: Sat Sep 24, 2005 8:35 pm    Post subject: Reply with quote

It works! 8)

Thanks a lot :D :wink:
Back to top
View user's profile Send private message
mascanho
Veteran
Veteran


Joined: 21 Dec 2004
Posts: 1241
Location: On my Bmx Bike on a Concrete Park Flatlanding ...

PostPosted: Wed Sep 28, 2005 4:36 pm    Post subject: Reply with quote

How do i apply the patch ??' thats the only thing im missing ...
_________________
Flatland Life is a Choice !
emerge avatar
Back to top
View user's profile Send private message
Nuteater
Apprentice
Apprentice


Joined: 25 Sep 2003
Posts: 193
Location: Jyväskylä, Finland

PostPosted: Thu Sep 29, 2005 6:53 pm    Post subject: Reply with quote

mascanho wrote:
How do i apply the patch ??' thats the only thing im missing ...

'man patch' will tell you.
_________________
I am Nuteater, hear me roar.
Back to top
View user's profile Send private message
mascanho
Veteran
Veteran


Joined: 21 Dec 2004
Posts: 1241
Location: On my Bmx Bike on a Concrete Park Flatlanding ...

PostPosted: Thu Sep 29, 2005 7:23 pm    Post subject: Reply with quote

tks that really saved my life !!!!
This is the thing, help like that is not welcome, 1st of all if im asking is because i really dont know, 2nd if everybody answered like you there would be no need for forums like these, so either you dont know it too, or you really want to be an a :roll: :roll: ! either way tank you very much but no tanks !!
_________________
Flatland Life is a Choice !
emerge avatar
Back to top
View user's profile Send private message
Nuteater
Apprentice
Apprentice


Joined: 25 Sep 2003
Posts: 193
Location: Jyväskylä, Finland

PostPosted: Thu Sep 29, 2005 8:59 pm    Post subject: Reply with quote

mascanho wrote:
tks that really saved my life !!!!
This is the thing, help like that is not welcome, 1st of all if im asking is because i really dont know, 2nd if everybody answered like you there would be no need for forums like these, so either you dont know it too, or you really want to be an a :roll: :roll: ! either way tank you very much but no tanks !!

First of all, sorry. I don't have a habit of giving 'RTFM' as an answer myself. I just looked at
your forum rank, and thought a nudge at the right direction (or a command in this case) would
easily suffice. (That, and the fact that I was a little appalled by your avatar.)

Okay. Patches are applied by the command 'patch'. Basic usage is
Code:
patch originalfile patchfile

which patches the originalfile with the patch at patchfile. You can also
just use
Code:
patch -p0 < patchfile

if the file to be patched is in the same directory as the patch. I hope this helps.
_________________
I am Nuteater, hear me roar.
Back to top
View user's profile Send private message
mascanho
Veteran
Veteran


Joined: 21 Dec 2004
Posts: 1241
Location: On my Bmx Bike on a Concrete Park Flatlanding ...

PostPosted: Thu Sep 29, 2005 10:08 pm    Post subject: Reply with quote

Tanks, now i really apreciate, i dont use to answer that way neither, its just that your answer seemd so "RTFM" and in certain way offencive , since in forums that not a "proper" answer, but i now perfectly understand you, and i accpet your appologies if you accept mines !
Peace my friend !

:wink:

PS: Tanks once again, patched and working like a charm, now i have rss on my menus and on my conky :P

PS2: How do i display more then one site of rss, and how do i set diferent colors for the title of the news and for the body of the news ???
_________________
Flatland Life is a Choice !
emerge avatar


Last edited by mascanho on Thu Sep 29, 2005 11:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
w0rm
n00b
n00b


Joined: 08 May 2004
Posts: 67

PostPosted: Thu Sep 29, 2005 10:38 pm    Post subject: Reply with quote

is there any ways to use this on gnome 2.12? conky isn't working with it:
* Conky doesn't work with window managers that
* take control over root window such as Gnome's nautilus.
any solutions?
Back to top
View user's profile Send private message
Nuteater
Apprentice
Apprentice


Joined: 25 Sep 2003
Posts: 193
Location: Jyväskylä, Finland

PostPosted: Fri Sep 30, 2005 12:45 pm    Post subject: Reply with quote

mascanho wrote:
PS2: How do i display more then one site of rss, and how do i set diferent colors for the title of the news and for the body of the news ???


If you put several configuration files to the ~/.rssdisplay directory, the shell script will parse the news
from all of them to the news listing. Setting the title to a different color is unfortunately not possible with
this setup. Sorry :).

w0rm wrote:
is there any ways to use this on gnome 2.12?

I don't know about that. For issues with conky itself you should probably contact
the conky developer.
_________________
I am Nuteater, hear me roar.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum