BBCodetoHTML Plugin Channel
From AwasuWiki
[edit]
Installation
- Install Python
- Create the two files listed below. It is recommended to put them into the `ChannelPlugins` directory under Awasu's installation directory.
- Program version 1.0
BBCodetoHTML.plugin:
[Config] AuthorName=Bobby van Dam AuthorEmailAddress=notlisted PluginNotes=This plug-in strips BB-Code from a RSS feed and tries to replace it so the content is shown in the correct way. Please understand that I'm no coding guru and this plugin was made and tested on one web site for my own use. ' -------------------------------------------------------------------------------- [ChannelParameterDefinition-1] Name=DownloadUrl Type=string DefaultValue= Description=The URL of the feed to be stripped from it's BBCode. [ChannelParameterDefinition-2] Name=DownloadUrl_UserName Type=string DefaultValue= Description=The username for the URL to be stripped form it's BBCode; leave blank if no authentication required. [ChannelParameterDefinition-3] Name=DownloadUrl_Password Type=string DefaultValue= Description=The password for the URL to be stripped form it's BBCode; leave blank if no authentication required.
BBCodetoHTML.py:
#awasuStripBBcode.py -- Channel plug-in to strip BB-Code from a RSS feed and convert it to HTML
#2007 by Bobby van Dam
#Thanks to Allan B. Wilson who's ChannelFeedEncoding script helped me a lot with making this one
#This script works for the website I created it for. I can't guarantee that it will work for you.
#You are free to change it so it will work better for you. Or maybe you will get some ideas from
#this script to make your own. ^_^
import urllib, os, win32api, sys
progpath = os.path.abspath(os.path.dirname(sys.argv[0]))
feedurl = win32api.GetProfileVal("ChannelParameters", "DownloadUrl", "", os.path.join(progpath,sys.argv[1]))
try:
input = urllib.urlopen(feedurl)
data = input.read()\
.replace("[list]","<ul>").replace("[*]","<li>").replace("[/list]","</ul>")\
.replace("[quote]","<blockquote>").replace("[/quote]","</blockquote>")\
.replace("[center]","<center>").replace("[/center]","</center>")\
.replace("[code]","<code>").replace("[/code]","</code>")\
.replace("[i]","<i>").replace("[/i]","</i>")\
.replace("[u]","<u>").replace("[/u]","</u>")\
.replace("[b]","<b>").replace("[/b]","</b>")\
.replace("<object","<a href='").replace("</object>","'></a>")\
.replace("[img]","<br/><br/><img src='").replace("[/img]","'align='center'><br/><br/>")\
.replace("<embed","<a href='").replace("</embed>","'></a>")\
.replace("]","**").replace("[/url**","</a>")\
.replace("[email=","<a href='mailto:").replace("[/email**","</a>")\
.replace("**","'>").replace("[url=","<a href='")
input.close()
except IOError:
print >>sys.stderr, "? Could not open URL: %s" % feedurl
sys.exit(2)
print data
[edit]
Usage
To use the BBCode plugin, select File -> New channel, then "Generated by a channel plugin", and browse to the BBCodetoHTML.py file. Add the feed URL in the plugin's URL parameter, and you're done.
It will turn this:
Into this:



