15__title__ =
"nasa_api - XPath and XSLT functions for the NASA RSS/HTML"
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
41 """Wraps a stream with an encoder"""
50 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
51 if isinstance(obj, str):
54 self.
out.buffer.write(obj)
59 """Delegate everything but write to the stream"""
60 return getattr(self.
out, attr)
62if isinstance(sys.stdout, io.TextIOWrapper):
67 from io
import StringIO
68 from lxml
import etree
70 sys.stderr.write(
'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
75 """Functions specific extending XPath
80 self.
regexPattern = re.compile(
'''Show\\ (?P<seasno>[0-9]+).*$''', re.UNICODE)
90 '''Parse the guid element and extract an episode number
91 Call example: 'mnvXpath:nasaTitleEp(string(title))'
92 return the a massaged title element
and an episode element
94 stripArray = ['HST SM4:',
'NASA 360:',
'NASA 360',
'NASA EDGE:',
'NASA EDGE',
'NE Live@',
'NE@',
'NASA Mission Update:',
"NASA TV's This Week @NASA," ]
96 for stripText
in stripArray:
97 title = title.replace(stripText,
'')
100 if title.startswith(
'Show'):
103 episodeNumber = match.groups()
104 episodeNumber = int(episodeNumber[0])
105 title = title[title.find(
':')+1:].strip()
107 mythtvNamespace =
"http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format"
108 mythtv =
"{%s}" % mythtvNamespace
109 NSMAP = {
'mythtv' : mythtvNamespace}
110 elementTmp = etree.Element(mythtv +
"mythtv", nsmap=NSMAP)
111 if not episodeNumber
is None:
112 etree.SubElement(elementTmp,
"title").text =
"EP%02d: %s" % (episodeNumber, title)
113 etree.SubElement(elementTmp, mythtv +
"episode").text =
"%s" % episodeNumber
115 etree.SubElement(elementTmp,
"title").text = title
def __getattr__(self, attr)
def __init__(self, outstream, encoding=None)
def nasaTitleEp(self, context, *arg)
Start of XPath extension functions.