In the example given in the previous section, the home URL and number of feed items to generate were hard-coded in the script. It is possible to add parameters to a plugin that can be set individually for each channel so now, we'll extend the script to let the user configure these two values.
Start the Channel Wizard and select the script SamplePythonChannel2.py. This time there will be an extra step in the wizard that lets you set the home URL and the number of feed 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:
[ChannelParameterDefinition-1] Name=HomeUrl Type=string DefaultValue=http://www.test.com Description=Our dummy home URL. [ChannelParameterDefinition-2] Name=nItems Type=int DefaultValue=15 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 values for 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:
[ChannelParameters] HomeUrl=http://www.test.com nItems=8
We now 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.