Will's blog

purpose: Will Kahn-Greene's blog of Miro, PyBlosxom, Python, GNU/Linux, random content, PyBlosxom, Miro, and other projects mixed in there ad hoc, half-baked, and with a twist of lemon

[ home | blog home | recent activity ]

Wed, 15 Jan 2003

pyblosxom api

Yesterday I slam-dunked some code to form some infrastructure for plugin modules--I figured I've done this for Lyntin and Stringbean, might as well go for the hat trick! The code allows us to build a set of callback chains and such to let people extend the functionality of pyblosxom without having to re-write pyblosxom internals. Blah blah standard plugin stuff.

At some point, I'll write a tutorial to use it beyond the brief documentation I left in the api module. Until then, I leave the following excerpt for how it all ties together using the pycalendar module as an example.


01: """
02: This is my fancy pyfortune module.  Basically what it's going to do
03: is call /usr/local/bin/fortune and populate the fortune variable
04: with the resulting string.
05: """
06: import commands
07: from libs import api, tools
08: 
09: class PyFortune:
10:   def __init__(self):
11:     self._fortune = None
12: 
13:   def getFortune(self, args):
14:     entry_dict = args[0]
15:     text_string = args[1]
16:     if self._fortune == None:
17:       self._fortune = commands.getoutput("/usr/games/fortune")
18: 
19:     return (entry_dict, tools.parse({"fortune": self._fortune}, text_string))
20: 
21: def initialize():
22:   api.parseitem.register(PyFortune().getFortune)

Figure 1: libs/plugins/pyfortune.py

Mmm... It occurs to me that this doesn't use the api module at all. On the other hand, it's pretty neat looking, so I'll leave it for now. At some point someone is going to have to remind me to write an api usage example.

Have a dynamically generated fortune:

...

This fortune has been removed because it turns out that dynamically generated text causes RSS feeds to think this is a new entry every time. Thus, no fortune for you!

Comments:

Post a new comment:

Three things:

  1. New comments get placed in a "draft" status and will NOT show up on the site until I explicitly approve it. Sometimes that happens within 24 hours.
  2. I reserve the right to reject/remove inappropriate comments.
  3. Sometimes I'll reply to a comment directly in email--so make sure your email address is correct.

If you can't for some reason post a comment, send me an email: willg at bluesock dot org.

Your name:


Your e-mail address (this doesn't get displayed to anyone--sometimes I'll reply directly to you):


URL of your website (optional):


Comment:


Yes, I am a human!


pyblosxom::1.5-dev git-master

Copyright 1996 to 2012, Will Guaraldi Kahn-Greene, under the Creative Commons BY-SA 3.0 license

Creative Commons License
Will's Blog by William Kahn-Greene is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.