15__title__ =
"spitzer_api - XPath and XSLT functions for the www.spitzer.caltech.edu grabber"
16__author__=
"R.D. Vaughan"
18This python script is intended to perform a variety of utility functions
19for the conversion of data to the MNV standard RSS output format.
20See this link for the specifications:
21http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format
29__xpathClassList__ = [
'xpathFunctions', ]
33__xsltExtentionList__ = []
35import os, sys, re, time, datetime, shutil,
urllib.request, urllib.parse, urllib.error, string
36from 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, str):
53 self.
out.buffer.write(obj)
58 """Delegate everything but write to the stream"""
59 return getattr(self.
out, attr)
61if isinstance(sys.stdout, io.TextIOWrapper):
66 from io
import StringIO
67 from lxml
import etree
69 sys.stderr.write(
'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
74 """Functions specific extending XPath
77 self.
functList = [
'spitzerLinkGeneration',
'spitzerThumbnailLink',
'spitzerCheckIfDBItem', ]
90 '''Generate a link for the www.spitzer.caltech.edu site.
91 Call example: 'mnvXpath:spitzerLinkGeneration(normalize-space(link), $paraMeter)'
97 tmpHandle = urllib.request.urlopen(webURL)
98 tmpHTML = str(tmpHandle.read(),
'utf-8')
100 except Exception
as errmsg:
101 sys.stderr.write(
"Error reading url(%s) error(%s)\n" % (webURL, errmsg))
105 findText =
"file=mp4:"
106 lenText = len(findText)
107 posText = tmpHTML.find(findText)
110 tmpHTML = tmpHTML[posText+lenText:]
111 tmpLink = tmpHTML[:tmpHTML.find(
'.')]
114 customHTML = common.linkWebPage(
'dummy',
'spitzer')
115 customHTML = customHTML.replace(
'TITLE', urllib.parse.quote(pageTitle))
116 customHTML = customHTML.replace(
'VIDEOCODE', tmpLink)
120 lenText = len(findText)
121 posText = tmpHTML.find(findText)
124 return customHTML.replace(
'IMAGE',
'')
125 tmpHTML = tmpHTML[posText+lenText:]
126 tmpImage = tmpHTML[:tmpHTML.find(
'"')]
127 self.
persistence[
'spitzerThumbnailLink'] =
'http://www.spitzer.caltech.edu%s' % tmpImage
129 return customHTML.replace(
'IMAGE', tmpImage)
133 '''Verify that the thumbnail actually exists. If it does not then use the site image.
134 Call example: 'mnvXpath:spitzerThumbnailLink('dummy
')'
135 return the thumbnail url
144 '''Use a unique key value pairing to find out if the 'internetcontentarticles' table already
145 has a matching item. This is done to save accessing the Internet when
not required.
146 Call example:
'mnvXpath:spitzerCheckIfDBItem(title, author, description)'
147 return True if a match was found
148 return False if a match was
not found
150 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)
def spitzerThumbnailLink(self, context, *args)
def spitzerLinkGeneration(self, context, *args)
Start of XPath extension functions.
def spitzerCheckIfDBItem(self, context, *arg)
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.