15 __title__ =
"nasa_api - XPath and XSLT functions for the NASA RSS/HTML"
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
96 self.
regexPattern = re.compile(
u'''Show\\ (?P<seasno>[0-9]+).*$''', re.UNICODE)
106 '''Parse the guid element and extract an episode number
107 Call example: 'mnvXpath:nasaTitleEp(string(title))'
108 return the a massaged title element and an episode element
110 stripArray = [
'HST SM4:',
'NASA 360:',
'NASA 360',
'NASA EDGE:',
'NASA EDGE',
'NE Live@',
'NE@',
'NASA Mission Update:',
"NASA TV's This Week @NASA," ]
112 for stripText
in stripArray:
113 title = title.replace(stripText,
u'')
114 title = title.strip()
116 if title.startswith(
'Show'):
119 episodeNumber = match.groups()
120 episodeNumber = int(episodeNumber[0])
121 title = title[title.find(
':')+1:].strip()
123 mythtvNamespace =
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format"
124 mythtv =
"{%s}" % mythtvNamespace
125 NSMAP = {
'mythtv' : mythtvNamespace}
126 elementTmp = etree.Element(mythtv +
"mythtv", nsmap=NSMAP)
127 if not episodeNumber
is None:
128 etree.SubElement(elementTmp,
"title").text =
u"EP%02d: %s" % (episodeNumber, title)
129 etree.SubElement(elementTmp, mythtv +
"episode").text =
u"%s" % episodeNumber
131 etree.SubElement(elementTmp,
"title").text = title