[mythtv-users] Finding gaps in the MythTV recording schedule to do maintenance in

Stephen Worthington stephen_agent at jsw.gen.nz
Sun Apr 23 11:25:02 UTC 2017


On Sun, 23 Apr 2017 03:17:34 +0000, you wrote:

>
>
>On 23/04/17 10:18, Bill Meek wrote:
>> ...
>> The Utilities.Send() function defaults to 6544. See this for an example
>> of how to pass command line arguments:
>>
>> https://www.mythtv.org/wiki/Python_API_Examples#Working_program_using_the_Dvr.2FGetUpcomingList_endpoint
>>
>> Or, you can just add the  port to this line, if you don't want
>> to pass it as a command line argument:
>>
>>     resp_dict = api.Send(host=HOST, port=1234, 
>> endpoint='Dvr/GetUpcomingList')
>>
>Ah, thanks Bill for the correction - my mistake.
>
>So that probably makes it a lot simpler. So if I wanted a command line 
>like this:
>gaps.py --duration 2 --host 127.0.0.1 --port 6544
>
>or
>gaps.py -d 2 -n 127.0.0.1 -p 6544
>
>this patch might do the trick?
>
>--- gaps.py    2017-04-23 12:32:53.453284798 +0930
>+++ gaps.py    2017-04-23 12:45:00.064720363 +0930
>@@ -15,8 +15,11 @@
>  import datetime
>  import dateutil.parser
>  import sys
>+import getopt
>
>  HOST = 'localhost'
>+PORT = '6544'
>+min_duration = datetime.timedelta(0)
>
>  class RecStatus(IntEnum):
>      Pending = -15
>@@ -87,17 +90,23 @@
>  # Main
>  ##############################################################################
>
>-args = len(sys.argv)
>-if args > 2:
>-    print('Error - too many command line arguments!')
>-    exit(2)
>-elif args == 2:
>-    min_duration = datetime.timedelta(0, 0, 0, 0, 0, float(sys.argv[1]))
>-    print('Searching for a minimum duration of '+str(min_duration))
>-else:
>-    min_duration = datetime.timedelta(0)
>+try:
>+    opts, args = 
>getopt.getopt(sys.argv[1:],"hd:n:p:",["help","duration=","host=","port="])
>+except getopt.GetoptError:
>+    print('gaps.py -d <duration> -n <host> -p <port>')
>+    sys.exit(2)
>+for opt, arg in opts:
>+    if opt in ("-h", "--help"):
>+        print('gaps.py -d <duration> -n <host> -p <port>')
>+        sys.exit()
>+    elif opt in ("-d", "--duration"):
>+        min_duration = datetime.timedelta(0, 0, 0, 0, 0, float(arg))
>+    elif opt in ("-n", "--host"):
>+        HOST = arg
>+    elif opt in ("-p", "--port"):
>+        PORT = arg
>
>-resp_dict = api.Send(host=HOST, endpoint='Dvr/GetUpcomingList')
>+resp_dict = api.Send(host=HOST, port=PORT, endpoint='Dvr/GetUpcomingList')
>
>  if list(resp_dict.keys())[0] in ['Abort', 'Warning']:
>      print('GetUpcomingList failed')
>
>
>
>Seems to work for me anyway (sample size = 1).
>$ /usr/local/bin/gaps.py -d 5.1 -n 192.168.1.101 -p 6546
>Gap:  start=Tue 2017-04-25 00:50:00+09:30  end=2017-04-25 
>05:58:00+09:30  duration=5:08:00
>Gap:  start=Wed 2017-04-26 00:45:00+09:30  end=2017-04-26 
>05:58:00+09:30  duration=5:13:00
>End of scheduled recordings                end=2017-04-30 02:10:00+09:30
>
>$ /usr/local/bin/gaps.py --duration 5.1 --host 192.168.1.101 --port 6546
>Gap:  start=Tue 2017-04-25 00:50:00+09:30  end=2017-04-25 
>05:58:00+09:30  duration=5:08:00
>Gap:  start=Wed 2017-04-26 00:45:00+09:30  end=2017-04-26 
>05:58:00+09:30  duration=5:13:00
>End of scheduled recordings                end=2017-04-30 02:10:00+09:30

The getopt package is obsolete - it has been replaced by argparse.  I
have uploaded a new version of gaps that does the above using
argparse, and also allows a second command line parameter giving the
number of minutes for the minimum duration.  So to search for gaps of
10 minutes or more, the command would be "gaps 0 10".  Both parameters
can be floating point numbers, so you could do something like "gaps
1.1 3.2" if you want, and it would search for a minimum gap duration
of 1h09m12s.

Here is the output of "gaps -h":

usage: gaps [-h] [-V] [-n HOST] [-p PORT] [hours] [minutes]

Find gaps in the MythTV recording schedule (Version: 1.3)

positional arguments:
  hours        Minimum gap duration to search for, in hours (floating
point
               allowed)
  minutes      Minimum gap duration to search for, in minutes
(floating point
               allowed)

optional arguments:
  -h, --help   show this help message and exit
  -V, --version
               display the version number and exit
  -n HOST, --host HOST
               MythTV backend hostname (default: mypvr)
  -p PORT, --port PORT
               MythTV backend API port number (default: 6544)

Note that the default values for -n and -p have been looked up in the
database if possible, so the above output shows the default for -n as
"mypvr" which is the name of my main MythTV box.  If access to the
database to look up the BackendStatusPort setting is not possible
there will be a warning message, and it will default to using
localhost and port 6544 instead, like the older versions.

I have also added a bit more error checking.


More information about the mythtv-users mailing list