[mythtv] Moving to Python 3 problems

Bill Meek keemllib at gmail.com
Fri Nov 30 19:36:42 UTC 2018


On 11/30/18 10:15 AM, Gary Buhrmaster wrote:
> Presuming that all the existing python bindings are
> still useful (and reviewing them should be step 0),
> the bindings and/or scripts that use bindings should
> possibly be migrated and/or refactored to use the
> services APIs where practical to avoid dealing
> with direct database access that at least some of
> the existing functionality uses (and where the services
> API is not sufficient, change the services API?).

For new programs, and for those that want to convert their
existing ones,

In v30-Pre, there is now a Services API module that cares for
access to the backend/frontend. Folks will have to learn the names
of the endpoints and parameters sent/returned. But that's similar to
the existing bindings. The API Wiki needs some work (I've got four
on my TODO list.)

The MythTV.services_api module is Python version agnostic.
But currently installs under 2.x (most likely x=7.) A symbolic
link makes it work for both v2 and v3

Normal Python help() works or an alias is my choice:
alias apihelp='echo -e "from MythTV.services_api import send\nhelp(send)" | python | less'

Examples, *very* simple, no error checking etc.:

#!/usr/bin/env python2 <----------------------------------
# -*- coding: utf-8 -*-

''' Very short v2 example that prints upcoming programs '''

from __future__ import print_function
from MythTV import MythBE

BACKEND = MythBE()
UPCOMING_COUNT = 0

for recording in BACKEND.getUpcomingRecordings():
     if recording.subtitle is None:
         recording.subtitle = ''
     print('  {0:<7.7}  {1:<14.14}{2:<27.27}  {3:<39.39}'
           .format(recording.callsign,
                   recording.starttime.strftime("%b %d %H:%M"),
                   recording.title.encode('utf-8'),
                   recording.subtitle.encode('utf-8')))
     UPCOMING_COUNT += 1

print('\n  Upcoming Shows: {}.\n'.format(UPCOMING_COUNT))



#!/usr/bin/env python3 <----------------------------------
# -*- coding: utf-8 -*-

''' Very short v3 example that prints upcoming programs '''

import sys
from MythTV.services_api import send as api, utilities as util

BACKEND = api.Send(host=sys.argv[1])

RESPONSE = BACKEND.send(endpoint='Dvr/GetUpcomingList')

COUNT = int(RESPONSE['ProgramList']['TotalAvailable'])

PROGS = RESPONSE['ProgramList']['Programs']

util.get_utc_offset(BACKEND)

for upcoming in range(COUNT):
     startts = util.utc_to_local(PROGS[upcoming]['Recording']['StartTs'])
     print('  {}  {:45.45}  {:15.15}'.format(
         startts,
         PROGS[upcoming]['Title'],
         PROGS[upcoming]['SubTitle']))

print('\nUpcoming Shows: {}.\n'.format(COUNT))

-- 
Bill


More information about the mythtv-dev mailing list