2009-11-25

Released: plagg 1.9

Download, Changelog.

Feeds, die relative URIs und kein base-Element aufweisen (z.B. der von Sam Ruby), generieren jetzt korrekte Links.

Hintergrund

In früheren Versionen hatte ich httpcache verwendet, um mit Hilfe der ETags- und Modified-Headern von HTTP überflüssige Feed-Transfers zu vermeiden. Das bewirkte aber, dass der feedparser die Original-URL nicht mehr zur Verfügung hatte, die nötig wäre, wenn der Feed selbst keine Base-URL enthält.

Jetzt erledigt der feedparser das Behandeln von ETags und Modified selbst und hat dadurch Zugriff auf alle für ein sauberes XML:Base-Handling notwendigen Angaben.

21:50 [/software/python] plagg_1_9 Google Trackback
Tags:

2006-12-22

My first Rhythmbox plugin

Yesterday evening I threw together my first Rhythmbox plugin! Like Luke’s InfoSender for Winamp, it posts the currently playing artist and song title to a webpage. I use it to update my sidebar.

Just put the Python source and config file (see below) into ~/.gnome2/rhythmbox/plugins or /usr/share/rhythmbox/plugins and restart Rhythmbox to enable the plugin. Its name is posttune.

To configure the plugin, change the BASE_URL variable to point to your own page. The artist’s name and song title are appended to BASE_URL, then the plugin makes a GET request to the URL.

[RB Plugin]
Loader=python
Module=posttune
IAge=1
Name=Tune poster
Description=Posts the current artist and song title to a web form
Authors=Beat Bolli <bbolli@ewanet.ch>
Copyright=Copyright 2006 Beat Bolli
Website=http://www.drbeat.li/py/

12:13 [/software/python] rhythmbox_posttune Google Trackback
Tags:

2006-03-26

Released: plagg 1.4

Download, Changelog.

Grösste Änderung: Link- und body-Ersetzungen sind jetzt eigene XML-Elemente unter einem <outline>-Element. Deshalb können sie auch mehrmals angegeben werden.

23:12 [/software/python] plagg_1_4 Google Trackback
Tags:

2006-01-21

Jabber-Client mit pyxmpp

Die Tatsache, dass Google Talk seit dieser Woche auch mit anderen Jabber-Servern kooperiert, hat mich dazu veranlasst, meinen bisherigen Client GAIM zu ghüderen und einen Jabber-Client zu installieren. Meine Wahl fiel auf Psi. Die Installation verlief problemlos, und meine bisherigen ICQ-Kontakte waren sofort wieder vorhanden.

Das Schöne an Jabber ist in meinen Augen ja, dass das Protokoll im Gegensatz zu AIM, MSN &c offen ist und es dashalb auch offene Bibliotheken dafür gibt. Also begann ich nach einem aptitude install python-pyxmpp, einen minimalen Client zu schreiben. Das war trotz der Library-Doku gar nicht so einfach, weil wirklich nur die API beschrieben ist und keine Konzepte und Zusammenhänge erklärt werden. Ich habs trotzdem geschafft:

#!/usr/bin/python
# -*- encoding: latin-1 -*-

import pyxmpp.all
import pyxmpp.jabber.all

config = dict(
    jid='bbolli@swissjabber.ch/bot',	# My Jabber ID
    pwd='secret*007',			# My password
    srv='swissjabber.ch',		# My Jabber server
    def_dest='bbolli@swissjabber.ch',	# Default destination
)


class msgClient(pyxmpp.jabber.Client):

    def stream_state_changed(self, state, arg):
	print 'stream state:', state, repr(arg)
	if state == 'authorized':
	    self.sendmsg()
	    self.disconnect()

    def sendmsg(self):
	m = pyxmpp.Message(from_jid=self.jid, to_jid=self.dest, body=self.msg)
	#m.set_type('chat')
	self.stream.send(m)


if __name__ == '__main__':
    import sys

    if len(sys.argv) == 1:
	sys.argv.append(config['def_dest'])
    elif sys.argv[1] in ('-h', '-help', '--help'):
	print >>sys.stderr, 'Usage: sabber [to_jid] [message]; uses stdin if no message'
	sys.exit(1)
    if len(sys.argv) == 2:
	sys.argv.append(sys.stdin.read())

    me = pyxmpp.JID(config['jid'])
    cl = msgClient(me, config['pwd'], config['srv'], disco_type='bot')

    cl.dest = pyxmpp.JID(sys.argv[1])
    cl.msg = ' '.join(sys.argv[2:])

    cl.connect()
    try:
	cl.loop()
    except KeyboardInterrupt:
	pass

12:46 [/software/python] python_jabber Google Trackback
Tags:

2005-01-02

plagg 1.3 ist da!

Download, Changelog.

Grösste Änderung: die Option -n schreibt eine Datei Latest.txt, in der alle neuen Einträge des letzten Runs mit Links auf die neuen Einträge aufgeführt sind.

20:50 [/software/python] plagg_1_3 Google Trackback

2004-11-25

plagg 1.2 ist da!

Download, Changelog.

Ganz nebenbei war dieser Release der vierhundertste commit in meinem subversion-Repository.

22:39 [/software/python] plagg_1_2 Google Trackback

2002-09-18

Aus dem Keller

Dieses Progrämmli habe ich vor Monaten mal gebraucht, um eine Signatur zu generieren. Heute bin ich wieder einmal darauf gestossen:

#!/usr/bin/python

"""
This program encodes a string reversably into a longint.

The goal is to write the reverse function as a Python one-liner so that
it fits in an email signature.

The idea is to convert each character of the string to one digit of the number.

The twist is this: the number's base depends on the string, and each digit
is offset so that the base becomes as small as possible. The offset is one less
than the lowest numbered ASCII code in the string. The base is two more
than the difference between highest and lowest ASCII code. This way, the
lowest code gets the digit value 1, the highest code gets the value (base - 1).

The reverse function u() recursively undoes this transformation.
"""

print
str = raw_input('Enter a string: ')
if not str:
    str = 'default test string'

# Convert the string to a list of ASCII codes.
codes = [ord(ch) for ch in str]

# Calculate offset and base.
ofs = min(codes) - 1
base = max(codes) + 1 - ofs

# Build the encoded number.
num = hex(reduce(lambda n, digit: base * n + digit - ofs, codes, 0L))

# Build the signature.
sig = """#!/usr/bin/python
def u(n, b, o): return n and u(n / b, b, o) + chr(n %% b + o) or ''
print u(%s, %d, %d)""" % (num, base, ofs)

print
print sig

# Verify.
print
exec sig
if u(eval(num), base, ofs) == str:
    print 'OK'
else:
    print 'not OK'

Das Ergebnis sieht für meine Mail-Adresse so aus:

#!/usr/bin/python
def u(n, b, o): return n and u(n / b, b, o) + chr(n % b + o) or ''
print u(0x90F8CA4FAD75C381BC173DA23L, 75, 45)

Das Dekodieren überlasse ich dem Leser als Übung!

00:31 [/software/python] mailsig Google Trackback