MythTV  master
technology.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # ----------------------
4 # Name: technology.py
5 # Python Script
6 # Author: R.D. Vaughan
7 # Purpose:
8 # This python script is intended to perform a mashup of various Technology Internet media sources
9 # for the MythTV Netvision plugin. It follows the MythTV Netvision grabber standards.
10 #
11 # Command example:
12 # See help (-u and -h) options
13 #
14 # Design:
15 # 1) Read "~/.mythtv/MythNetvision/userGrabberPrefs/technologyMashup.xml" configuration file
16 # 2) Input the sources that are marked as enabled
17 # 3) Process the results and display to stdout
18 #
19 #
20 # License:Creative Commons GNU GPL v2
21 # (http://creativecommons.org/licenses/GPL/2.0/)
22 #-------------------------------------
23 __title__ ="Technology";
24 __mashup_title__ = "technologyMashup"
25 __author__="R.D. Vaughan"
26 __version__="0.10"
27 # 0.10 Initial development
28 
29 __usage_examples__ ='''
30 (Option Help)
31 > ./technology.py -h
32 Usage: ./technology.py -hduvlST [parameters] <search text>
33 Version: v0.XX Author: R.D.Vaughan
34 
35 For details on the MythTV Netvision plugin see the wiki page at:
36 http://www.mythtv.org/wiki/MythNetvision
37 
38 Options:
39  -h, --help show this help message and exit
40  -d, --debug Show debugging info (URLs, raw XML ... etc, info
41  varies per grabber)
42  -u, --usage Display examples for executing the script
43  -v, --version Display grabber name and supported options
44  -l LANGUAGE, --language=LANGUAGE
45  Select data that matches the specified language fall
46  back to English if nothing found (e.g. 'es' EspaƱol,
47  'de' Deutsch ... etc). Not all sites or grabbers
48  support this option.
49  -p PAGE NUMBER, --pagenumber=PAGE NUMBER
50  Display specific page of the search results. Default
51  is page 1. Page number is ignored with the Tree View
52  option (-T).
53  -T, --treeview Display a Tree View of a sites videos
54 
55 > ./technology.py -v
56 <grabber>
57  <name>Technology</name>
58  <author>R.D. Vaughan</author>
59  <thumbnail>technology.png</thumbnail>
60  <command>technology.py</command>
61  <type>video</type>
62  <description>Mashups combines media from multiple sources to create a new work</description>
63  <version>0.XX</version>
64  <search>true</search>
65  <tree>true</tree>
66 </grabber>
67 
68 Search:
69 > ./technology.py -S "Video"
70 
71 Treeview:
72 > ./technology.py -T
73 '''
74 __search_max_page_items__ = 20
75 __tree_max_page_items__ = 20
76 
77 import sys, os
78 
79 
80 class OutStreamEncoder(object):
81  """Wraps a stream with an encoder"""
82  def __init__(self, outstream, encoding=None):
83  self.out = outstream
84  if not encoding:
85  self.encoding = sys.getfilesystemencoding()
86  else:
87  self.encoding = encoding
88 
89  def write(self, obj):
90  """Wraps the output stream, encoding Unicode strings with the specified encoding"""
91  if isinstance(obj, unicode):
92  try:
93  self.out.write(obj.encode(self.encoding))
94  except IOError:
95  pass
96  else:
97  try:
98  self.out.write(obj)
99  except IOError:
100  pass
101 
102  def __getattr__(self, attr):
103  """Delegate everything but write to the stream"""
104  return getattr(self.out, attr)
105 sys.stdout = OutStreamEncoder(sys.stdout, 'utf8')
106 sys.stderr = OutStreamEncoder(sys.stderr, 'utf8')
107 
108 
109 # Used for debugging
110 #import nv_python_libs.common.common_api
111 try:
112  '''Import the common python class
113  '''
114  import nv_python_libs.common.common_api as common_api
115 except Exception, e:
116  sys.stderr.write('''
117 The subdirectory "nv_python_libs/common" containing the modules common_api.py and
118 common_exceptions.py (v0.1.3 or greater),
119 They should have been included with the distribution of MythNetvision
120 Error(%s)
121 ''' % e)
122  sys.exit(1)
123 if common_api.__version__ < '0.1.3':
124  sys.stderr.write("\n! Error: Your current installed common_api.py version is (%s)\nYou must at least have version (0.1.3) or higher.\n" % target.__version__)
125  sys.exit(1)
126 
127 
128 # Used for debugging
129 #import nv_python_libs.mashups.mashups_api as target
130 try:
131  '''Import the python mashups support classes
132  '''
133  import nv_python_libs.mashups.mashups_api as target
134 except Exception, e:
135  sys.stderr.write('''
136 The subdirectory "nv_python_libs/mashups" containing the modules mashups_api and
137 mashups_exceptions.py (v0.1.0 or greater),
138 They should have been included with the distribution of technology.py.
139 Error(%s)
140 ''' % e)
141  sys.exit(1)
142 if target.__version__ < '0.1.0':
143  sys.stderr.write("\n! Error: Your current installed mashups_api.py version is (%s)\nYou must at least have version (0.1.0) or higher.\n" % target.__version__)
144  sys.exit(1)
145 
146 # Verify that the main process modules are installed and accessible
147 try:
148  import nv_python_libs.mainProcess as process
149 except Exception, e:
150  sys.stderr.write('''
151 The python script "nv_python_libs/mainProcess.py" must be present.
152 Error(%s)
153 ''' % e)
154  sys.exit(1)
155 
156 if process.__version__ < '0.2.0':
157  sys.stderr.write("\n! Error: Your current installed mainProcess.py version is (%s)\nYou must at least have version (0.2.0) or higher.\n" % process.__version__)
158  sys.exit(1)
159 
160 if __name__ == '__main__':
161  # No api key is required
162  apikey = ""
163  # Set the base processing directory that the grabber is installed
164  target.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ ))
165  # Make sure the target functions have an instance of the common routines
166  target.common = common_api.Common()
167  main = process.mainProcess(target, apikey, )
168  main.grabberInfo = {}
169  main.grabberInfo['title'] = __title__
170  main.grabberInfo['command'] = u'technology.py'
171  main.grabberInfo['mashup_title'] = __mashup_title__
172  main.grabberInfo['author'] = __author__
173  main.grabberInfo['thumbnail'] = 'technology.png'
174  main.grabberInfo['type'] = ['video', ]
175  main.grabberInfo['desc'] = u"Mashups combines media from multiple sources to create a new work"
176  main.grabberInfo['version'] = __version__
177  # Check if there are any Nature items in the DB to to actually search
178  main.grabberInfo['search'] = target.common.checkIfDBItem('dummy', {'feedtitle': __title__, })
179  main.grabberInfo['tree'] = True
180  main.grabberInfo['html'] = False
181  main.grabberInfo['usage'] = __usage_examples__
182  main.grabberInfo['SmaxPage'] = __search_max_page_items__
183  main.grabberInfo['TmaxPage'] = __tree_max_page_items__
184  main.main()
def __getattr__(self, attr)
Definition: technology.py:102
def __init__(self, outstream, encoding=None)
Definition: technology.py:82