<commit_before>#!/usr/bin/env python
# encoding: UTF-8

from datetime import datetime, timedelta
import json

import requests

import sarpur
from sarpur import scraper, api, logger  # noqa
import util.player as player
from util.gui import GUI
from util import strptime

INTERFACE = GUI(sarpur.ADDON_HANDLE, sarpur.BASE_URL)
EVENT_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S'


def index():
    """
    The front page (i.e. the first one the user sees when opening the plugin)
    """

    INTERFACE.add_dir(u'Beinar útsendingar', 'view_live_index', '')
    INTERFACE.add_dir(u'Sarpur forsíða', 'view_featured', '')
    INTERFACE.add_dir(u'Flokkar', 'view_categories', '')
    INTERFACE.add_dir(u'RÚV', 'view_schedule', 'ruv')
    INTERFACE.add_dir(u'RÚV 2', 'view_schedule', 'ruv2')
    INTERFACE.add_dir(u'Útvarp', 'view_radio', '')
    INTERFACE.add_dir(u'Leita', 'search', '')


def view_featured(action_value, name):
    for panel in api.featured_panels():
        INTERFACE.add_dir(panel['title'], 'view_panel', panel['slug'])


def view_panel(panel_slug, name):
    for program in api.panel_programs(panel_slug):
        INTERFACE.add_program_episode(program, program['episodes'][0])


def view_categories(action_value, name):
    for category in api.categories():
        INTERFACE.add_dir(category['title'], 'view_category', category['slug'])


def view_category(category_slug, name):
    for program in api.category_programs(category_slug):
        INTERFACE.add_program_episode(program, program['episodes'][0])


def view_live_index(action_value, name):
    """
    List of available live streams
    """
    INTERFACE.add_item(u'RÚV', 'play_live_stream', 'ruv')
    INTERFACE.add_item(u'RÚV 2', 'play_live_stream', 'ruv2')
    INTERFACE.add_item(u'RÁS 1', 'play_live_stream', 'ras1')
    INTERFACE.add_item(u'RÁS 2', 'play_live_stream', 'ras2')
    INTERFACE.add_item(u'Rondó', 'play_live_stream', 'rondo')<commit_msg>Only display program episode if program has episodes<commit_after>#!/usr/bin/env python
# encoding: UTF-8

from datetime import datetime, timedelta
import json

import requests

import sarpur
from sarpur import scraper, api, logger  # noqa
import util.player as player
from util.gui import GUI
from util import strptime

INTERFACE = GUI(sarpur.ADDON_HANDLE, sarpur.BASE_URL)
EVENT_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S'


def index():
    """
    The front page (i.e. the first one the user sees when opening the plugin)
    """

    INTERFACE.add_dir(u'Beinar útsendingar', 'view_live_index', '')
    INTERFACE.add_dir(u'Sarpur forsíða', 'view_featured', '')
    INTERFACE.add_dir(u'Flokkar', 'view_categories', '')
    INTERFACE.add_dir(u'RÚV', 'view_schedule', 'ruv')
    INTERFACE.add_dir(u'RÚV 2', 'view_schedule', 'ruv2')
    INTERFACE.add_dir(u'Útvarp', 'view_radio', '')
    INTERFACE.add_dir(u'Leita', 'search', '')


def view_featured(action_value, name):
    for panel in api.featured_panels():
        INTERFACE.add_dir(panel['title'], 'view_panel', panel['slug'])


def view_panel(panel_slug, name):
    for program in api.panel_programs(panel_slug):
        if program['episodes']:
            INTERFACE.add_program_episode(program, program['episodes'][0])


def view_categories(action_value, name):
    for category in api.categories():
        INTERFACE.add_dir(category['title'], 'view_category', category['slug'])


def view_category(category_slug, name):
    for program in api.category_programs(category_slug):
        if program['episodes']:
            INTERFACE.add_program_episode(program, program['episodes'][0])


def view_live_index(action_value, name):
    """
    List of available live streams
    """
    INTERFACE.add_item(u'RÚV', 'play_live_stream', 'ruv')
    INTERFACE.add_item(u'RÚV 2', 'play_live_stream', 'ruv2')
    INTERFACE.add_item(u'RÁS 1', 'play_live_stream', 'ras1')
    INTERFACE.add_item(u'RÁS 2', 'play_live_stream', 'ras2')
    INTERFACE.add_item(u'Rondó', 'play_live_stream', 'rondo')
{'fraction_non_alphanumeric': 0.14086648087154802, 'fraction_numerical': 0.005573853559665568, 'mean_word_length': 4.840236686390533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2122365', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1405, 'n_words': 286}