You are not logged in.

#1 2008-03-28 16:11:24

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

more pipe-menus for openbox

hello openbox users!

here are some pipe-menus i've written in python:
1) checkmail:

DESCRIPTION:
This program checks (only one) IMAP4 server for new mails and displays mail headers through pyosd.
(I've tested it so far with cyrus, dovecot, communigate, gmail)

first you have to copy and edit the ~/.checkmailrc file. read the README. there is an english and german version.

2) processes.py:

Description:
    This script pipes a process manipulation menu into the openbox menu.

Usage:
    Just place this script in ~/.config/openbox/scripts, make it executable; if you want you can enlist the processes
    which should not be shown in the unwanted_procs list below, then add following to your ~/.config/openbox/menu.xml:
    "<menu id="proc-menu" label="processes" execute="~/.config/openbox/scripts/processes.py" />...
    <menu id="root-menu" label="Openbox3">...<menu id="proc-menu" />...</menu>"
    and reconfigure openbox.
    To enable cpu usage display uncomment the lines marked with (***) (lines 104-106 and 144).
      Note: You need 'ps'.
    To enable cpulimit just uncomment the lines marked with (#*#) (lines 156-167).
      Note: You need 'cpulimit'. Get it from here: "http://cpulimit.sourceforge.net"

because it's a python script, you have to be careful with the indentation when uncommenting.

3) feeder.py:

Description:
    This script pipes rss and podcast feeds into the openbox menu

you have to edit the "User set variables": rss_feeds, browser and media-player used to open feeds and podcasts. this script uses temp-files (cache) for faster access through pipe menu. you can choose whether you want to use this or not (either cache = 1 or cache = 0).

i use 1) and 3) as cronjobs with the "--update" flag:
for 3) put in "crontab -e" smth like:

*      */3     *       *       *           for i in `ls ~/.config/openbox/scripts/feeder_*py` ; do nice -n 19 python $i --update ; done > /dev/null 2>&1

this checks for new feeds every thrre hours.
i have different feeder.py scripts, one for news, linux-stuff, podacsts (feeder_news.py, feeder_lunix.py, feeder_video_podcast.py). i think it's faster.
for 1) i have smth like:

*/10    *       *       *       *          export DISPLAY=:0.0; python ~/.config/openbox/scripts/checkmail.py --update > /dev/null 2>&1

this checks for new mails every ten minutes.
"export DISPLAY" is needed for osd.

obviously you need python, for 1) and 3) you need the python-feedparser and python-elementtree modules.

enjoy!
feedback is welcome.

vlad

Last edited by DonVla (2008-03-29 14:38:51)

Offline

#2 2008-03-30 14:50:57

ep2011
Member
Registered: 2008-02-28
Posts: 66

Re: more pipe-menus for openbox

Thanks the processes one is amazing! Just what I wanted.

I didn't test the others though as I don't use feeds and use gmail so I already have a script using rss.

Offline

#3 2008-03-30 16:29:03

yettenet
Member
Registered: 2007-05-17
Posts: 129

Re: more pipe-menus for openbox

Great scripts, thanks! smile

Offline

#4 2008-03-30 21:11:52

yettenet
Member
Registered: 2007-05-17
Posts: 129

Re: more pipe-menus for openbox

Hello again, I've noticed that your feedparser leaves out the first entry of feeds apparently for no reason. Could it be fixed?

Example: When I should get 5 entries, like A, B, C, D and E, I only see B, C, D and E.

Offline

#5 2008-03-31 11:52:14

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

Re: more pipe-menus for openbox

hmm,
could you post your rss_url list. i haven't noticed this problem so far...

vlad

Offline

#6 2008-03-31 12:23:05

yettenet
Member
Registered: 2007-05-17
Posts: 129

Re: more pipe-menus for openbox

It's totally regardless of what I use, it happens with each one of them.

Offline

#7 2008-03-31 12:50:56

dlb
Member
Registered: 2006-04-07
Posts: 10

Re: more pipe-menus for openbox

The processes script is really great!
thanks!

Offline

#8 2008-03-31 12:51:28

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

Re: more pipe-menus for openbox

paste your script somewhere (pastebin.com).for now i have no idea what does not work. i should take a look at your options etc. as  i said i haven't noticed this problem so far.
vlad

Last edited by DonVla (2008-03-31 12:52:25)

Offline

#9 2008-03-31 13:01:22

yettenet
Member
Registered: 2007-05-17
Posts: 129

Re: more pipe-menus for openbox

Here ya go, I haven't modified anything apart from User variables tongue

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
#-------------------------------------------------------------------------------

feeder.py - version 5
by Vlad George

#-------------------------------------------------------------------------------

Description:
    This script pipes rss and podcast feeds into the openbox menu

Usage:
    First you need the python-feedparser and python-elementtree modules (ubuntu/ archlinux (AUR)),
    place this script in ~/.config/openbox/scripts, make it executable, insert the urls of the feeds
    you want to read in the rss_urls list below, then add following to your ~/.config/openbox/menu.xml:
    "<menu id="feeder-menu" label="rss-feeds" execute="~/.config/openbox/scripts/feeder.py" />...
    <menu id="root-menu" label="Openbox3">...<menu id="feeder-menu" />...</menu>"
    and reconfigure openbox.

Changelog:
    01.07.2007:   1st version
    03.07.2007:   works now (changed "~")....
    05.07.2007:   added cache
    07.10.2007:   added name of rss and sorted output
    03.2008:      added podcast support

#-------------------------------------------------------------------------------

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
http://www.fsf.org/

"""
#-------------------------------------------------------------------------------             
#                             User set variables
#-------------------------------------------------------------------------------             


## your rss feeds:
rss_urls = [
            #('name to be shown', 'url of rss'),
            #('Arch Packages', 'http://www.archlinux.org/feeds/packages/'),
            ('TV2', 'http://tv.animare.hu/rssfeed.aspx?tartalom=aktualistvmusor&tvcsatorna=3'),
        ('RTL Klub', 'http://tv.animare.hu/rssfeed.aspx?tartalom=aktualistvmusor&tvcsatorna=5'),
        ('Viasat3', 'http://tv.animare.hu/rssfeed.aspx?tartalom=aktualistvmusor&tvcsatorna=16'),
        ('M1', 'http://tv.animare.hu/rssfeed.aspx?tartalom=aktualistvmusor&tvcsatorna=1'),
         ]

## browser and audio/video-player to use:
# open_with = "gnome-open"
open_with = "opera"
play_with = "mplayer"

## how many entries should be shown:
rss_feeds_count = 60

## use cache (1 enabled, 0 disabled)
cache = 1

### if cache enabled:

## how old should cache files get - in minutes; set to 0 for manual refresh:
## you can also use >> feeder.py --update << to only update the cache file (useful as cronjob)
age = 30

## temporary directory for cache file (default=/tmp/); leave it as it is.
cache_dir = "/tmp"

#-------------------------------------------------------------------------------
#                                   Script
#-------------------------------------------------------------------------------


def gettingTitles(url_list):
    # get feeds for each url:
    rss_dict = {}
    for i in xrange(len(url_list)):

        rss = feedparser.parse(url_list[i][1])
        rss_entry = []
        try:
            append = rss_entry.append
            if rss.entries[i].has_key('link') == False:
                [append((rss.entries[num].title, None, rss.entries[num].enclosures[0].href)) for num in xrange(rss_feeds_count)]
            elif rss.entries[i].has_key('enclosures') == False:
                [append((rss.entries[num].title, rss.entries[num].link, None)) for num in xrange(rss_feeds_count)]
            else:
                [append((rss.entries[num].title, rss.entries[num].link, rss.entries[num].enclosures[0].href)) for num in xrange(rss_feeds_count)]
        except IndexError:
            pass
        try:
            if url_list[i][0] == '':
                rss_dict[(rss.feed.title, url_list[i][1])] = rss_entry[1:int(rss_feeds_count)]
            else:
                rss_dict[(url_list[i][0], url_list[i][1])] = rss_entry[1:int(rss_feeds_count)]
        except:
            pass
    # rss_dict-items: { ..., ([i][0]:> rss-url, [i][1]:> rss-name):[..., ([i][j][0]:> entry-title, [i][j][1]:> entry-link, [i][j][2]:> entry-podcast_link), ...], ... }
    return rss_dict


def generateXml(dict_url_entry, outfile):
    # sort dict items according display name
    sorted_list = dict_url_entry.items()
    sorted_list.sort()
    # [ ..., (([i][0][0] -> rss-name, [i][0][1] -> rss-url), [..., ([i][1][j][0] -> entry-title, [i][1][j][1] -> entry-link, [i][1][j][2]:> entry-podcast_link), ...]), ... ]
    root = ET.Element("openbox_pipe_menu")
    for i in xrange(len(sorted_list)):
        menu = ET.SubElement(root,"menu", attrib = {"id" : sorted_list[i][0][1], "label" : unicode(sorted_list[i][0][0])})
        for j in xrange(len(sorted_list[i][1])):
            try:
                if sorted_list[i][1][j][2] == None:
                    item = ET.SubElement(menu, "item", attrib = {"label" : unicode(sorted_list[i][1][j][0])})
                    action = ET.SubElement(item, "action", attrib = {"name" : "Execute"})
                    command = ET.SubElement(action, "command")
                    tmp = str(sorted_list[i][1][j][1]).replace('~','%7E')
                    command.text = "%s %s" % (open_with, tmp)
                elif sorted_list[i][1][j][1] == None:
                    podcast_menu = ET.SubElement(menu, "menu", attrib = {"id" : str(int(random.random()*10000000)) + "-menu", "label" : unicode(sorted_list[i][1][j][0])})
                    podcast_play = ET.SubElement(podcast_menu, "item", attrib = {"label" : " play podcast"})
                    podcast_play_action = ET.SubElement(podcast_play, "action", attrib = {"name": "Execute"})
                    podcast_play_execute = ET.SubElement(podcast_play_action, "command")
                    tmp = str(sorted_list[i][1][j][2]).replace('~','%7E')
                    podcast_play_execute.text = "%s %s" % (play_with, tmp)
                else:
                    podcast_menu = ET.SubElement(menu, "menu", attrib = {"id" : str(int(random.random()*10000000)) + "-menu", "label" : unicode(sorted_list[i][1][j][0])})
                    podcast_open = ET.SubElement(podcast_menu, "item", attrib = {"label" : " open "})
                    podcast_open_action = ET.SubElement(podcast_open, "action", attrib = {"name": "Execute"})
                    podcast_open_execute = ET.SubElement(podcast_open_action, "command")
                    tmp1 = str(sorted_list[i][1][j][1]).replace('~','%7E')
                    podcast_open_execute.text = "%s %s" % (open_with, tmp1)
                    podcast_play = ET.SubElement(podcast_menu, "item", attrib = {"label" : " play podcast"})
                    podcast_play_action = ET.SubElement(podcast_play, "action", attrib = {"name": "Execute"})
                    podcast_play_execute = ET.SubElement(podcast_play_action, "command")
                    tmp2 = str(sorted_list[i][1][j][2]).replace('~','%7E')
                    podcast_play_execute.text = "%s %s" % (play_with, tmp2)
            except IndexError:
                pass
    if cache == 1:
        separator = ET.SubElement(root,"separator")
        refresh = ET.SubElement(root,"item", attrib = {"label":"Reload Cache"})
        action2 = ET.SubElement(refresh,"action",attrib = {"name":"Execute"})
        command2 = ET.SubElement(action2,"command")
        command2.text = "%s %s" % (sys.argv[0], "--update")
    tree = ET.ElementTree(root)
    tree.write(outfile)


def ageCheck(age_in_min, file_to_check):
    age_in_sec = int(age_in_min)*60
    file_age = int(time())-int(os.path.getmtime(file_to_check))
    if age_in_min == 0:
        return 1
    elif os.path.isfile(file_to_check) and file_age < age_in_sec:
        return 1
    else:
        return 0


def printXml(xml_entry):
    temp_file = file(xml_entry,'r')
    a = temp_file.read()
    temp_file.close()
    print a


#-------------------------------------------------------------------------------             
#                                    Main
#-------------------------------------------------------------------------------             
import os.path, sys, feedparser
import elementtree.ElementTree as ET
import random
from time import time

#-------------------------#
if __name__ == "__main__" :
#-------------------------#
    if cache == 1:
        cache_file = cache_dir + "/." + str(os.path.split(sys.argv[0])[1]) + "-" + str(os.getuid()) + ".cache"
        if ('--update' in sys.argv[1:]):
            generateXml(gettingTitles(rss_urls), cache_file)
        elif os.path.isfile(cache_file) and ageCheck(age, cache_file):
            print '<?xml version="1.0" encoding="UTF-8"?>'
            printXml(cache_file)
        else:
            generateXml(gettingTitles(rss_urls), cache_file)
            print '<?xml version="1.0" encoding="UTF-8"?>'
            printXml(cache_file)
    else:
        print '<?xml version="1.0" encoding="UTF-8"?>'
        generateXml(gettingTitles(rss_urls), sys.stdout)

Offline

#10 2008-04-01 11:41:42

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

Re: more pipe-menus for openbox

hmm, strange. i've copy and pasted the script above and here it runs w/o problems, alll four links are shown...
here is a sample of one of my rss-scripts. try this one and please tell me if there are also entries missing.

vlad

Offline

#11 2008-04-01 12:16:25

yettenet
Member
Registered: 2007-05-17
Posts: 129

Re: more pipe-menus for openbox

Nah, you misunderstood me. I was trying to say that when an rss feed should display # entries, the script shows #-1 entries.

Offline

#12 2008-04-01 14:28:37

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

Re: more pipe-menus for openbox

d'oh! i see.

ps: changed. good old python trap. counting starts with 0...
should work now as expected.

vlad

Last edited by DonVla (2008-04-01 14:38:52)

Offline

#13 2008-04-01 15:31:19

yettenet
Member
Registered: 2007-05-17
Posts: 129

Re: more pipe-menus for openbox

yayz, great! big_smile

Offline

#14 2008-04-09 18:09:03

nightm4re
Member
Registered: 2005-12-30
Posts: 42
Website

Re: more pipe-menus for openbox

a distro specific forum is really not the place for these.  you should consider (if it's not done already) adding these to the openbox pipe menu wiki page.

Offline

#15 2008-04-13 22:43:56

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

Re: more pipe-menus for openbox

nightm4re wrote:

a distro specific forum is really not the place for these.  you should consider (if it's not done already) adding these to the openbox pipe menu wiki page.

done!

vlad

Offline

Board footer

Powered by FluxBB