15 __title__ =
"spitzer_api - XPath and XSLT functions for the www.spitzer.caltech.edu grabber" 16 __author__=
"R.D. Vaughan" 18 This python script is intended to perform a variety of utility functions 19 for the conversion of data to the MNV standard RSS output format. 20 See this link for the specifications: 21 http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format 29 __xpathClassList__ = [
'xpathFunctions', ]
33 __xsltExtentionList__ = []
35 import os, sys, re, time, datetime, shutil, urllib, string
36 from copy
import deepcopy
40 """Wraps a stream with an encoder""" 49 """Wraps the output stream, encoding Unicode strings with the specified encoding""" 50 if isinstance(obj, unicode):
62 """Delegate everything but write to the stream""" 63 return getattr(self.
out, attr)
68 from StringIO
import StringIO
69 from lxml
import etree
71 sys.stderr.write(
u'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
79 for digit
in etree.LIBXML_VERSION:
80 version+=str(digit)+
'.' 81 version = version[:-1]
84 ! Error - The installed version of the "lxml" python library "libxml" version is too old. 85 At least "libxml" version 2.7.2 must be installed. Your version is (%s). 91 """Functions specific extending XPath 94 self.
functList = [
'spitzerLinkGeneration',
'spitzerThumbnailLink',
'spitzerCheckIfDBItem', ]
107 '''Generate a link for the www.spitzer.caltech.edu site. 108 Call example: 'mnvXpath:spitzerLinkGeneration(normalize-space(link), $paraMeter)' 114 tmpHandle = urllib.urlopen(webURL)
115 tmpHTML =
unicode(tmpHandle.read(),
'utf-8')
117 except Exception, errmsg:
118 sys.stderr.write(
u"Error reading url(%s) error(%s)\n" % (webURL, errmsg))
122 findText =
u"file=mp4:" 123 lenText = len(findText)
124 posText = tmpHTML.find(findText)
127 tmpHTML = tmpHTML[posText+lenText:]
128 tmpLink = tmpHTML[:tmpHTML.find(
'.')]
131 customHTML = common.linkWebPage(
'dummy',
'spitzer')
132 customHTML = customHTML.replace(
'TITLE', urllib.quote(pageTitle))
133 customHTML = customHTML.replace(
'VIDEOCODE', tmpLink)
137 lenText = len(findText)
138 posText = tmpHTML.find(findText)
141 return customHTML.replace(
'IMAGE',
u'')
142 tmpHTML = tmpHTML[posText+lenText:]
143 tmpImage = tmpHTML[:tmpHTML.find(
'"')]
144 self.
persistence[
'spitzerThumbnailLink'] =
u'http://www.spitzer.caltech.edu%s' % tmpImage
146 return customHTML.replace(
'IMAGE', tmpImage)
150 '''Verify that the thumbnail actually exists. If it does not then use the site image. 151 Call example: 'mnvXpath:spitzerThumbnailLink('dummy')' 152 return the thumbnail url 161 '''Use a unique key value pairing to find out if the 'internetcontentarticles' table already 162 has a matching item. This is done to save accessing the Internet when not required. 163 Call example: 'mnvXpath:spitzerCheckIfDBItem(title, author, description)' 164 return True if a match was found 165 return False if a match was not found 167 return common.checkIfDBItem(
'dummy', {
'feedtitle':
'Space',
'title': arg[0],
'author': arg[1],
'description': arg[2]})
def __init__(self, outstream, encoding=None)
def __getattr__(self, attr)
long long copy(QFile &dst, QFile &src, uint block_size)
Copies src file to dst file.
def spitzerThumbnailLink(self, context, *args)
def spitzerLinkGeneration(self, context, *args)
Start of XPath extension functions.
def spitzerCheckIfDBItem(self, context, *arg)