Skip to content

frontend

Hika van den Hoven edited this page May 5, 2017 · 10 revisions

Creating a Frontend

Below you see the Dutch/Flemish frontend and you can almost completely copy that. You only have to adapt a few things:

  • At line 25/26 you have to adapt for the backend version you are writing the frontend for.
  • Al line 30 and further in the Configure class you adapt the values to match your frontend. Most is self explaining.
  • First a description as returned by the --description option and your frontend version.
  • self.opt_dict['output_tz'] Follows the naming and directory structure used in Linux, probably at /usr/share/zoneinfo
  • self.source_url is the location where your grabber_datafile can be downloaded. If the sourcefiles themselves are somewhere else, that can be set in that file.
  • self.datafile is the name of your grabber_datafile with .json appended to it.
  • self.update_url is where a user can find updates. It will be mentioned in the log if there are any.
  • self.compat_text is the text that will be appended to the xmltvIDs if the user sets the compat flag. It is also settable in your grabber datafile through the compat_text keyword

Next you continue to create a grabber_datafile.

The Dutch/Flemish frontend

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

# Python 3 compatibility
from __future__ import unicode_literals

# Modules we need
import sys, locale, tvgrabpyAPI

try:
    unichr(42)
except NameError:
    unichr = chr    # Python 3

# check Python version
if sys.version_info[:3] < (2,7,9):
    sys.stderr.write("tv_grab_py_API requires Pyton 2.7.9 or higher\n")
    sys.exit(2)

if sys.version_info[:2] >= (3,0):
    sys.stderr.write("tv_grab_py_API does not yet support Pyton 3 or higher.\nExpect errors while we proceed\n")

locale.setlocale(locale.LC_ALL, '')

if tvgrabpyAPI.version()[1:4] < (1,0,0):
    sys.stderr.write("tv_grab_nl3_py requires tv_grab_py_API 1.0.0 or higher\n")
    sys.exit(2)

class Configure(tvgrabpyAPI.Configure):
    def __init__(self):
        # We need these in __init__ to determin log names etc. If not set here prior to running __init__ we use defaults
        tvgrabpyAPI.Configure.__init__(self, name = 'tv_grab_nl3_py', datafile = 'tv_grab_nl')
        # Version info and description from the frontend as returned by the version function
        self.country = 'The Netherlands'
        self.description = 'Dutch/Flemish grabber combining multiple sources.'
        self.major = 3
        self.minor = 0
        self.patch = 1
        self.patchdate = u'20160802'
        self.alfa = False
        self.beta = True
        # The default timezone to use in the xmltv output file. Can be overruled in the users configuration.
        self.opt_dict['output_tz'] = 'Europe/Amsterdam'
        # Where to get the json datafile and updates (if different from the API location)
        self.source_url = 'https://raw.githubusercontent.com/tvgrabbers/sourcematching/master'
        self.update_url = 'https://github.com/tvgrabbers/tvgrabpyAPI/releases/latest'
        self.compat_text = '.tvgids.nl'

# end Configure()

# allow this to be a module
if __name__ == '__main__':
    config = Configure()
    x = tvgrabpyAPI.grabber_main(config)
    config.close()
    sys.exit(x)

Clone this wiki locally