<commit_before>import sys
import json
from datetime import datetime

from resources.lib.kodihelper import KodiHelper
import routing

base_url = sys.argv[0]
handle = int(sys.argv[1])
helper = KodiHelper(base_url, handle)
plugin = routing.Plugin()
info_locale = helper.c.locale.split('_')[0]


def run():
    try:
        if helper.check_for_prerequisites():
            plugin.run()
    except helper.c.CMoreError as error:
        helper.log('C More Error: {error}'.format(error=str(error)))
        if str(error) == 'User is not authenticated':
            helper.login_process()
            plugin.run()
        else:
            helper.dialog('ok', helper.language(30028), str(error))


@plugin.route('/')
def root():
    page_map = {
        'start': {'name': helper.language(30020), 'func': list_carousels},
        'movies': {'name': helper.language(30021), 'func': list_pages},
        'series': {'name': helper.language(30022), 'func': list_carousels},
        'sports': {'name': helper.language(30023), 'func': list_pages},
        'tv': {'name': helper.language(30024), 'func': list_channels},
        'programs': {'name': helper.language(30025), 'func': list_carousels},
        'kids': {'name': helper.language(30026), 'func': list_carousels}
    }

    for page in helper.c.pages[helper.c.locale]:
        if page in page_map:
            helper.add_item(page_map[page]['name'], plugin.url_for(page_map[page]['func'], page=page))

    helper.add_item(helper.language(30030), plugin.url_for(search))
    helper.eod()


@plugin.route('/list_carousels')
def list_carousels():
    if 'namespace' in plugin.args:
        namespace = plugin.args['namespace'][0]
    else:
        namespace = 'page'
    carousels = helper.c.get_carousels(plugin.args['page'][0], namespace)
    for carousel, params in carousels.items():
        helper.add_item(carousel, plugin.url_for(list_assets, params=json.dumps(params)))
    helper.eod()


@plugin.route('/list_channels')
def list_channels():
    channels = helper.c.get_channels()
    for channel in channels:
        for program in channel['schedules']:
            if datetime.now() >= helper.c.parse_datetime(program['calendarDate']):
                current_program = program['program']
                break
        info = {
            'mediatype': 'episode',
            'title': current_program['title'],
            'plot': current_program['shortSynopsis'],
            'duration': current_program['duration'],
            'season': current_program['seasonNumber'],
            'episode': current_program['episodeNumber']<commit_msg>fix current program logic<commit_after>import sys
import json
from datetime import datetime

from resources.lib.kodihelper import KodiHelper
import routing

base_url = sys.argv[0]
handle = int(sys.argv[1])
helper = KodiHelper(base_url, handle)
plugin = routing.Plugin()
info_locale = helper.c.locale.split('_')[0]


def run():
    try:
        if helper.check_for_prerequisites():
            plugin.run()
    except helper.c.CMoreError as error:
        helper.log('C More Error: {error}'.format(error=str(error)))
        if str(error) == 'User is not authenticated':
            helper.login_process()
            plugin.run()
        else:
            helper.dialog('ok', helper.language(30028), str(error))


@plugin.route('/')
def root():
    page_map = {
        'start': {'name': helper.language(30020), 'func': list_carousels},
        'movies': {'name': helper.language(30021), 'func': list_pages},
        'series': {'name': helper.language(30022), 'func': list_carousels},
        'sports': {'name': helper.language(30023), 'func': list_pages},
        'tv': {'name': helper.language(30024), 'func': list_channels},
        'programs': {'name': helper.language(30025), 'func': list_carousels},
        'kids': {'name': helper.language(30026), 'func': list_carousels}
    }

    for page in helper.c.pages[helper.c.locale]:
        if page in page_map:
            helper.add_item(page_map[page]['name'], plugin.url_for(page_map[page]['func'], page=page))

    helper.add_item(helper.language(30030), plugin.url_for(search))
    helper.eod()


@plugin.route('/list_carousels')
def list_carousels():
    if 'namespace' in plugin.args:
        namespace = plugin.args['namespace'][0]
    else:
        namespace = 'page'
    carousels = helper.c.get_carousels(plugin.args['page'][0], namespace)
    for carousel, params in carousels.items():
        helper.add_item(carousel, plugin.url_for(list_assets, params=json.dumps(params)))
    helper.eod()


@plugin.route('/list_channels')
def list_channels():
    channels = helper.c.get_channels()
    for channel in channels:
        programs = [x for x in channel['schedules'] if datetime.now() >= helper.c.parse_datetime(x['calendarDate'])]
        if programs:
            current_program = programs[-1]['program']
        else:
            continue  # no current live program
        info = {
            'mediatype': 'episode',
            'title': current_program['title'],
            'plot': current_program['shortSynopsis'],
            'duration': current_program['duration'],
            'season': current_program['seasonNumber'],
            'episode': current_program['episodeNumber']
{'fraction_non_alphanumeric': 0.15359664186224004, 'fraction_numerical': 0.019271131463461173, 'mean_word_length': 3.2376717865804365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '774645', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1586, 'n_words': 331}