Difference between revisions of "XmlCleaner Plugin Channel"

From AwasuWiki
Jump to: navigation, search
(Installation)
m (Installation: Formatting correction)
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
 
* Install [http://www.python.org/ Python], [http://sourceforge.net/projects/pywin32/ PyWin32], and [http://utidylib.berlios.de/ uTidyLib].
 
* Install [http://www.python.org/ Python], [http://sourceforge.net/projects/pywin32/ PyWin32], and [http://utidylib.berlios.de/ uTidyLib].
 +
** uTidyLib contains an older version of the [http://starship.python.net/crew/theller/ctypes/ ctypes] Python module. The included version works fine with Python 2.3, but for Python 2.4, ctypes should be updated to a newer version.
 
* 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.
  
Line 17: Line 18:
  
 
[ChannelParameterDefinition-1]
 
[ChannelParameterDefinition-1]
Name=URL
+
Name=DownloadUrl
 
Type=string
 
Type=string
 
DefaultValue=
 
DefaultValue=
Line 38: Line 39:
 
tidyopts = dict(output_xml=1, input_xml=1, add_xml_decl=1, indent=1, tidy_mark=0, output_encoding='utf8')
 
tidyopts = dict(output_xml=1, input_xml=1, add_xml_decl=1, indent=1, tidy_mark=0, output_encoding='utf8')
  
# Get the feed URL from the plugin configuration:
+
# Awasu will already have downloaded the DownloadUrl and stored it into a
url = win32api.GetProfileVal("ChannelParameters","URL","",sys.argv[1])
+
# temporary file pointed to by DownloadUrlFile. Get the file name:
 +
filename = win32api.GetProfileVal("System","DownloadUrlFile","",sys.argv[1])
  
page = urllib.urlopen(url, proxies=proxies)
+
# Then read the file:
 +
page = file(filename,'rb')
 
xml = ''
 
xml = ''
 
block = 'a'
 
block = 'a'
Line 48: Line 51:
 
     xml = xml + block
 
     xml = xml + block
 
page.close()
 
page.close()
 +
 
# Clean up the HTML:
 
# Clean up the HTML:
 
xml = tidy.parseString(xml, **tidyopts)
 
xml = tidy.parseString(xml, **tidyopts)

Latest revision as of 09:06, 20 June 2006

This plugin corrects errors in an XML feed.


Installation

  • Install Python, PyWin32, and uTidyLib.
    • uTidyLib contains an older version of the ctypes Python module. The included version works fine with Python 2.3, but for Python 2.4, ctypes should be updated to a newer version.
  • Create the two files listed below. It is recommended to put them into the `ChannelPlugins` directory under Awasu's installation directory.

XmlCleaner.plugin:

[Config]
AuthorName=Tomi Junnila
AuthorEmailAddress=notlisted
PluginNotes=This plugin uses uTidylib to clean up an erroneous XML feed

' --------------------------------------------------------------------------------

[ChannelParameterDefinition-1]
Name=DownloadUrl
Type=string
DefaultValue=
Description=URL to read erroneous feed from.

XmlCleaner.py:

# -*- coding: iso-8859-1 -*-

import sys, win32api
import socket
from xml.dom.minidom import parseString
import urllib
from datetime import datetime,tzinfo,timedelta
import time as _time
import tidy

# Set options for uTidyLib
tidyopts = dict(output_xml=1, input_xml=1, add_xml_decl=1, indent=1, tidy_mark=0, output_encoding='utf8')

# Awasu will already have downloaded the DownloadUrl and stored it into a
# temporary file pointed to by DownloadUrlFile. Get the file name:
filename = win32api.GetProfileVal("System","DownloadUrlFile","",sys.argv[1])

# Then read the file:
page = file(filename,'rb')
xml = ''
block = 'a'
while block!='':
    block = page.read()
    xml = xml + block
page.close()

# Clean up the HTML:
xml = tidy.parseString(xml, **tidyopts)
print xml

Usage

To use the XmlCleaner plugin, select File -> New channel, then "Generated by a channel plugin", and browse to the XmlCleaner.py file. Add the feed URL in the plugin's URL parameter, and you're done.