[Pipemenu OB]Feeder.py (Résolu)

Xorg, Compiz, KDE / Gnome / Xfce / Fluxbox / e17 / fvwm ... GDM/KDM/XDM...
Répondre
Skwad
archer de cavalerie
Messages : 195
Inscription : mar. 14 déc. 2010, 20:00

[Pipemenu OB]Feeder.py (Résolu)

Message par Skwad »

Bonjour,

Depuis un bon moment (ça a déjà été fonctionnel), feeder.py ne m'affiche plus rien, comme le montre ce screenshot :
Image

J'ai repris l'original du lien ci-dessus, pour être sûr que mes modifs n'y sont pour rien.

L'extrait de mon menu.xml

Code : Tout sélectionner

<menu execute="python2 ~/.script/feeder2.py" id="pipe-11538" label="RSS Feeds"/>
python2 : 2.7.1-9
Est en conflit avec : python3
python2-feedparser : 5.0.1-3
libxml2 : 2.7.8-1

Est-ce possible que python3 en soit la cause ? Lorsque j'essaie de le supprimer :

Code : Tout sélectionner

[skwad@arch ~]$ yaourt -R python3
Erreur: 'python3': target not found

Merci.
En attendant, je vais tenter de me renseigner pour python3.



EDIT : Ok, j'ai trouvé.

Code : Tout sélectionner

yaourt -Qi python
Nom                   : python
Version               : 3.2-2
C'est donc pas ça.

Je vais fouiller du côté de libxml2 avec un conky.



EDIT2 : Rhaa je m'embrouille, j'arrive pas à savoir dans quel(s) cas conky en a besoin. Suis paumé. Help.
Dernière modification par Skwad le sam. 16 juil. 2011, 14:37, modifié 1 fois.
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
Drexya
archer de cavalerie
Messages : 161
Inscription : sam. 20 juin 2009, 15:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Drexya »

Skwad
archer de cavalerie
Messages : 195
Inscription : mar. 14 déc. 2010, 20:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Skwad »

Quand je dis "Depuis un bon moment", c'est 3-4 mois pas plus puisque j'ai Arch depuis le début de l'année seulement. Ça a bien marché pendant un bon mois.

La news étant paru bien avant, je doute que ça m'aide mais merci quand même de t'être intéressé à mon problème. De plus, j'étais pas au courant de ça.


Sinon pour faire avancer le schmilblik :

Code : Tout sélectionner

[skwad@arch ~]$ python2 .script/feeder2.py 
<?xml version="1.0" encoding="UTF-8"?>
<openbox_pipe_menu><menu id="http://www.archlinux.org/feeds/packages/" label="Arch Packages" /></openbox_pipe_menu>[skwad@arch ~]$
Cela veut bien dire que python2 n'y est pour rien non ?
Voilà pourquoi je mets à chercher ailleurs...
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
Drexya
archer de cavalerie
Messages : 161
Inscription : sam. 20 juin 2009, 15:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Drexya »

Tu as remplacé

Code : Tout sélectionner

#!/usr/bin/env python
par

Code : Tout sélectionner

#!/usr/bin/env python2
à la 1ère ligne du script ?
Skwad
archer de cavalerie
Messages : 195
Inscription : mar. 14 déc. 2010, 20:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Skwad »

Oui, ça change rien.
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
Skwad
archer de cavalerie
Messages : 195
Inscription : mar. 14 déc. 2010, 20:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Skwad »

:up:
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
Skwad
archer de cavalerie
Messages : 195
Inscription : mar. 14 déc. 2010, 20:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Skwad »

Sous debian/openbox, voici ce que me renvoie la commande :

Code : Tout sélectionner

$ python2.6 .script/feeder2.py 
<?xml version="1.0" encoding="UTF-8"?>
<openbox_pipe_menu><menu id="http://www.archlinux.org/feeds/packages/" label="Arch Packages"><item label="unbound 1.4.12-1 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/community/x86_64/unbound/</command></action></item><item label="unbound 1.4.12-1 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/community/i686/unbound/</command></action></item><item label="libcups 1.4.7-2 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/x86_64/libcups/</command></action></item><item label="cups 1.4.7-2 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/x86_64/cups/</command></action></item><item label="cups 1.4.7-2 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/i686/cups/</command></action></item><item label="libcups 1.4.7-2 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/i686/libcups/</command></action></item><item label="enigma 1.04-3 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/community/x86_64/enigma/</command></action></item><item label="dopewars 1.5.12-5 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/community/x86_64/dopewars/</command></action></item><item label="enigma 1.04-3 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/community/i686/enigma/</command></action></item><item label="dopewars 1.5.12-5 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/community/i686/dopewars/</command></action></item><item label="asymptote 2.13-1 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/x86_64/asymptote/</command></action></item><item label="asymptote 2.13-1 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/i686/asymptote/</command></action></item><item label="perl-yaml 0.73-1 any"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/any/perl-yaml/</command></action></item><item label="perl-log-log4perl 1.33-1 any"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/any/perl-log-log4perl/</command></action></item><item label="netcfg 2.6.4-1 any"><action name="Execute"><command>chromium http://www.archlinux.org/packages/testing/any/netcfg/</command></action></item><item label="octave 3.4.2-2 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/x86_64/octave/</command></action></item><item label="octave 3.4.2-2 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/extra/i686/octave/</command></action></item><item label="usbutils 003-1 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/core/x86_64/usbutils/</command></action></item><item label="usbutils 003-1 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/core/i686/usbutils/</command></action></item><item label="pygtk 2.24.0-2 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/testing/x86_64/pygtk/</command></action></item><item label="python-numpy 1.6.0-1 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/testing/x86_64/python-numpy/</command></action></item><item label="python2-numpy 1.6.0-1 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/testing/x86_64/python2-numpy/</command></action></item><item label="python-numpy 1.6.0-1 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/testing/i686/python-numpy/</command></action></item><item label="python2-numpy 1.6.0-1 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/testing/i686/python2-numpy/</command></action></item><item label="pygtk 2.24.0-2 i686"><action name="Execute"><command>chromium http://www.archlinux.org/packages/testing/i686/pygtk/</command></action></item><item label="python-paramiko 1.7.7.1-1 any"><action name="Execute"><command>chromium http://www.archlinux.org/packages/community/any/python-paramiko/</command></action></item><item label="lib32-r128-dri 7.11rc1-3 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/multilib-testing/x86_64/lib32-r128-dri/</command></action></item><item label="lib32-libgl 7.11rc1-3 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/multilib-testing/x86_64/lib32-libgl/</command></action></item><item label="lib32-tdfx-dri 7.11rc1-3 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/multilib-testing/x86_64/lib32-tdfx-dri/</command></action></item><item label="lib32-sis-dri 7.11rc1-3 x86_64"><action name="Execute"><command>chromium http://www.archlinux.org/packages/multilib-testing/x86_64/lib32-sis-dri/</command></action></item></menu></openbox_pipe_menu>
Et voici sous arch :

Code : Tout sélectionner

$ python2.7 .config/openbox/pipemenus/feeder2.py 
<?xml version="1.0" encoding="UTF-8"?>
<openbox_pipe_menu><menu id="http://www.archlinux.org/feeds/packages/" label="Arch Packages" /></openbox_pipe_menu>
Config debian : python2.6 + python-feedparser
Config arch : python2.7 + python2-feedparser
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
Avatar de l’utilisateur
benjarobin
Maître du Kyudo
Messages : 17596
Inscription : sam. 30 mai 2009, 15:48
Localisation : Lyon

Re: [Pipemenu OB]Feeder.py (en cours)

Message par benjarobin »

Cette ligne de code me retourne bien quelque chose

Code : Tout sélectionner

/usr/lib/python2.7/site-packages/feedparser.py http://www.archlinux.org/feeds/packages/
Je pense que ton problème est dans ton script que tu utilise : .config/openbox/pipemenus/feeder2.py
Zsh | KDE | PC fixe : AMD Ryzen 9900X, Radeon RX 7700 XT
Titre d'un sujet : [Thème] Sujet (état) / Règles du forum
Avatar de l’utilisateur
tuxce
Maître du Kyudo
Messages : 6677
Inscription : mer. 12 sept. 2007, 16:03

Re: [Pipemenu OB]Feeder.py (en cours)

Message par tuxce »

Celui de l'url indiquée au départ : http://www.nakamura-gebiet.de/scripts/feeder.py
a une erreur, il s'arrête à la première entrée.
Remplace:

Code : Tout sélectionner

            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)]
Par:

Code : Tout sélectionner

            else:
                [append((rss.entries[num].title, rss.entries[num].link, None)) for num in xrange(rss_feeds_count)]
Skwad
archer de cavalerie
Messages : 195
Inscription : mar. 14 déc. 2010, 20:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Skwad »

Euh, mais sous debian, ça roule et j'ai repris le feeder2.py de ma Arch.
De plus, tuxce :

Code : Tout sélectionner

[skwad@arch ~]$ python2.7 .config/openbox/pipemenus/feeder2.py 
  File ".config/openbox/pipemenus/feeder2.py", line 104
    [append((rss.entries[num].title, rss.entries[num].link, None) for num in xrange(rss_feeds_count)]
                                                                                                    ^
SyntaxError: invalid syntax
Et je le répète mais ça a déjà fonctionné tel quel.
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
Avatar de l’utilisateur
tuxce
Maître du Kyudo
Messages : 6677
Inscription : mer. 12 sept. 2007, 16:03

Re: [Pipemenu OB]Feeder.py (en cours)

Message par tuxce »

J'avais oublié une ")" je l'ai rajouté.
Skwad
archer de cavalerie
Messages : 195
Inscription : mar. 14 déc. 2010, 20:00

Re: [Pipemenu OB]Feeder.py (en cours)

Message par Skwad »

Eh bien, énorme merci tuxce, c'est nickel ! :bravo:


Ci-dessous donc, l'intégralité du script revu et corrigé pour ceux que ça intéresserait :

Code : Tout sélectionner

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

feeder.py - version 6
by Vlad George

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

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

Usage:
    First you need the python-feedparser module (archlinux [extra]/ ubuntu).
    Place this script under ~/.config/openbox/scripts, edit the variables under "User set variables"
    according to your likings (your list of rss_urls, browser and media-player to open links,
    number of displayed rss-entries, enable/disable caching of feeds, maximum age of feeds),
    make it executable, 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
    06.2008:      uses python's internal python-feedparser module

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

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/'),
         ]

## browser and audio/video-player to use:
# open_with = "gnome-open"
open_with = "chromium"
play_with = "audacious -e"

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

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

### 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 = 120

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


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


# {{{ ##  fold marker start

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)]
            else:
                [append((rss.entries[num].title, rss.entries[num].link, None)) 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[0:int(rss_feeds_count)]
            else:
                rss_dict[(url_list[i][0], url_list[i][1])] = rss_entry[0: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 xml.etree.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)


# }}} ##  fold marker end

# vim: set ft=python ts=4 sw=4 foldmethod=marker :
OS : Archlinux / Debian
DE : Gnome / KDE
Serveur : OpenMediaVault
Répondre