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

Mark Perkins perkins1724 at hotmail.com
Sun Apr 23 03:17:34 UTC 2017



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


More information about the mythtv-users mailing list