Plugin parameters

In the example given in the previous section, the home URL and number of feed items to generate are hard-coded in the script. It is possible to add parameters to a plugin that can be set individually for each channel so we'll now extend the script to allow the user to configure these two values.

Start the Channel Wizard and select the script This time there will be an extra step in the wizard that allows you to set the home URL and number of items to generate.

To define plugin parameters, you simply need to create a file in the same directory that has the same name as the script but with a ".plugin" extension. It should look something like this:

Description=Our dummy home URL.

Description=The number of dummy feed items to generate.
Each section defines a new parameter and can be repeated as many times as required. The exact format of this file is given in the appendix.

When the script is run, it receives a single command-line parameter, the path to an INI file that contains the settings of these parameters for the channel requesting the feed. For this example, if the user had changed the number of items to generate but left the home URL with the default value, the plugin will be given an INI file that might look like this:


We then simply need to modify the script to read these values from the INI file:

# get the name of the INI file
configFilename = sys.argv[1]

# get our channel parameters
HOME_URL = win32api.GetProfileVal( "ChannelParameters" , "HomeUrl" , "" , configFilename )
NFEEDITEMS = win32api.GetProfileVal( "ChannelParameters" , "nItems" , 0 , configFilename )

# the rest of the script is the same...

Now you can create as many channels as you like using the same script but with different parameters.