Difference between revisions of "BBCodetoHTML Plugin Channel"

From AwasuWiki
Jump to: navigation, search
(Installation)
(Installation)
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
* Install [http://www.python.org/ Python]
 
* Install [http://www.python.org/ Python]
 
* Create the two files listed below. It is recommended to put them into the `ChannelPlugins` directory under Awasu's installation directory.
 
* 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''':
 
'''BBCodetoHTML.plugin''':
Line 14: Line 15:
  
 
[ChannelParameterDefinition-1]
 
[ChannelParameterDefinition-1]
Name=Feed URL
+
Name=DownloadUrl
 
Type=string
 
Type=string
Description=The URL of the feed to be stripped from it's BB-Code.
+
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.
 
</pre>
 
</pre>
  
Line 34: Line 48:
  
  
feedurl = win32api.GetProfileVal("ChannelParameters", "Feed URL", "", os.path.join(progpath,sys.argv[1]))
+
feedurl = win32api.GetProfileVal("ChannelParameters", "DownloadUrl", "", os.path.join(progpath,sys.argv[1]))
  
  
Line 42: Line 56:
 
input = urllib.urlopen(feedurl)
 
input = urllib.urlopen(feedurl)
 
data = input.read()\
 
data = input.read()\
  .replace("[list]","&lt;ul&gt;").replace("[*]","&lt;li&gt;").replace("[/list]","&lt;/ul&gt;")\
+
  .replace("[list]","&amp;lt;ul&amp;gt;").replace("[*]","&amp;lt;li&amp;gt;").replace("[/list]","&amp;lt;/ul&amp;gt;")\
  .replace("[quote]","&lt;blockquote&gt;").replace("[/quote]","&lt;/blockquote&gt;")\
+
  .replace("[quote]","&amp;lt;blockquote&amp;gt;").replace("[/quote]","&amp;lt;/blockquote&amp;gt;")\
  .replace("[center]","&lt;center&gt;").replace("[/center]","&lt;/center&gt;")\
+
  .replace("[center]","&amp;lt;center&amp;gt;").replace("[/center]","&amp;lt;/center&amp;gt;")\
  .replace("[code]","&lt;code&gt;").replace("[/code]","&lt;/code&gt;")\
+
  .replace("[code]","&amp;lt;code&amp;gt;").replace("[/code]","&amp;lt;/code&amp;gt;")\
  .replace("[i]","&lt;i&gt;").replace("[/i]","&lt;/i&gt;")\
+
  .replace("[i]","&amp;lt;i&amp;gt;").replace("[/i]","&amp;lt;/i&amp;gt;")\
  .replace("[u]","&lt;u&gt;").replace("[/u]","&lt;/u&gt;")\
+
  .replace("[u]","&amp;lt;u&amp;gt;").replace("[/u]","&amp;lt;/u&amp;gt;")\
  .replace("[b]","&lt;b&gt;").replace("[/b]","&lt;/b&gt;")\
+
  .replace("[b]","&amp;lt;b&amp;gt;").replace("[/b]","&amp;lt;/b&amp;gt;")\
  .replace("&amp;lt;object","&lt;a href='").replace("&amp;lt;/object&amp;gt;","'&gt;&lt;/a&gt;")\
+
  .replace("&amp;lt;object","&amp;lt;a href='").replace("&amp;lt;/object&amp;gt;","'&amp;gt;&amp;lt;/a&amp;gt;")\
  .replace("[img]","&lt;br/&gt;&lt;br/&gt;&lt;img src='").replace("[/img]","'align='center'&gt;&lt;br/&gt;&lt;br/&gt;")\
+
  .replace("[img]","&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;img src='").replace("[/img]","'align='center'&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;")\
  .replace("&amp;lt;embed","&lt;a href='").replace("&amp;lt;/embed&amp;gt;","'&gt;&lt;/a&gt;")\
+
  .replace("&amp;lt;embed","&amp;lt;a href='").replace("&amp;lt;/embed&amp;gt;","'&amp;gt;&amp;lt;/a&amp;gt;")\
  .replace("]","**").replace("[/url**","&lt;/a&gt;")\
+
  .replace("]","**").replace("[/url**","&amp;lt;/a&amp;gt;")\
  .replace("[email=","&lt;a href='mailto:").replace("[/email**","&lt;/a&gt;")\
+
  .replace("[email=","&amp;lt;a href='mailto:").replace("[/email**","&amp;lt;/a&amp;gt;")\
  .replace("**","'&gt;").replace("[url=","&lt;a href='")  
+
  .replace("**","'&amp;gt;").replace("[url=","&amp;lt;a href='")  
 
input.close()
 
input.close()
 
except IOError:
 
except IOError:

Latest revision as of 16:54, 12 March 2007

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]","&lt;ul&gt;").replace("[*]","&lt;li&gt;").replace("[/list]","&lt;/ul&gt;")\
	  .replace("[quote]","&lt;blockquote&gt;").replace("[/quote]","&lt;/blockquote&gt;")\
	  .replace("[center]","&lt;center&gt;").replace("[/center]","&lt;/center&gt;")\
	  .replace("[code]","&lt;code&gt;").replace("[/code]","&lt;/code&gt;")\
	  .replace("[i]","&lt;i&gt;").replace("[/i]","&lt;/i&gt;")\
	  .replace("[u]","&lt;u&gt;").replace("[/u]","&lt;/u&gt;")\
	  .replace("[b]","&lt;b&gt;").replace("[/b]","&lt;/b&gt;")\
	  .replace("&lt;object","&lt;a href='").replace("&lt;/object&gt;","'&gt;&lt;/a&gt;")\
	  .replace("[img]","&lt;br/&gt;&lt;br/&gt;&lt;img src='").replace("[/img]","'align='center'&gt;&lt;br/&gt;&lt;br/&gt;")\
	  .replace("&lt;embed","&lt;a href='").replace("&lt;/embed&gt;","'&gt;&lt;/a&gt;")\
	  .replace("]","**").replace("[/url**","&lt;/a&gt;")\
	  .replace("[email=","&lt;a href='mailto:").replace("[/email**","&lt;/a&gt;")\
	  .replace("**","'&gt;").replace("[url=","&lt;a href='") 
	input.close()
except IOError:
	print >>sys.stderr, "? Could not open URL: %s" % feedurl
	sys.exit(2)


print data

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:

Image1.jpg

Into this:

Image2.jpg

Image3.jpg