We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

Creating Channel Providers for effbot.exe/effnews

January 8, 2003 | Fredrik Lundh

Release 0.9 of the effnews RSS reader adds support for pluggable channel providers. Providers are simply Python scripts that process data from an external source, and present it to the application as if it were an RSS file.

Using a Channel Provider

The provider mechanism is used to control how data is read from a given URL. Each provider is associated with one or more URLs. For example, the Daily Python-URL provider is associated with the http://www.pythonware.com/daily/index.htm URL.

To use an installed provider, just drag the source URI to the EffNews window as usual. EffNews will now use the provider to fetch data, instead of the standard RSS reader.

Writing Simple Channel Providers

Providers should be installed in the c:/effbot.exe/effnews directory, and must use the .provider extension. The actual filename doesn’t matter; the application loads all provider scripts, and uses data in the script to figure out what provider to use for a given URL.

The current version only supports the simpleprovider protocol. This protocol uses the standard HTTP transport to read data from the source, and passes the data to a parser function which turns it into an RSS-style channel header and a list of RSS-style items. To implement a channel provider, create a Python module which defines two names:

urls

This variable should contain a list of URLs associated with this provider.

simpleprovider

This function is used to parse the data. It is called with two arguments: a context object, and the text to parse. The context object has a single public method, called push. This method is used to add RSS-style channel and item elements to the internal database.

Example:

import re

urls = [
    "http://www.mysite.com/channel.html"
]

pattern = r"..."

def simpleprovider(context, text):
    context.push("channel", title="my channel", link=urls[0])
    for title, body in re.findall(pattern, text):
        context.push("item", title=title, description=body)

The push method takes an RSS element name (“channel” or “item”), and one or more keyword arguments which provide RSS subelements.

The channel element can have title, link, and description subelements. All subelements are optional.

The item element can have title, link, and description subelements. You must specify at least one of the title or description elements. The link element is always optional.

Element values should be either ASCII strings, or Unicode strings. Do not use encoded 8-bit strings. Embedded HTML is allowed, but should be avoided.

If the provider cannot parse the input data, it should raise an appropriate Python exception.