<commit_before>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # noqa pylint: disable=unused-import, redefined-builtin

import logging

from flexget import plugin
from flexget.event import event
from flexget.utils.template import get_template


log = logging.getLogger('notify_task')


class NotifyTask(object):
    schema = {
        'type': 'object',
        'properties': {
            'title': {
                'type': 'string',
                'default': '[FlexGet] {{task.name}}:'
                           '{%if task.failed %} {{task.failed|length}} failed entries.{% endif %}'
                           '{% if task.accepted %} {{task.accepted|length}} new entries downloaded.{% endif %}'},
            'template': {'type': 'string', 'default': 'default.template'},
            'to': {
                'type': 'array', 'items':
                    {'allOf': [
                        {'$ref': '/schema/plugins?group=notifiers'},
                        {'maxProperties': 1,
                         'error_maxProperties': 'Plugin options indented 2 more spaces than the first letter of the'
                                                ' plugin name.',
                         'minProperties': 1}]}}

        },
        'required': ['to']
    }

    def on_task_notify(self, task, config):
        if not (task.accepted or task.failed):
            log.verbose('No accepted or failed entries, not sending a notification.')
        plugin.get_plugin_by_name('notify').instance.send_notification(config['title'],
                                                                       get_template(config['template'], 'task'),
                                                                       template_renderer=task.render)


@event('plugin.register')
def register_plugin():
    plugin.register(NotifyTask, 'notify_task', api_ver=2)<commit_msg>Don't send task notifications for uninteresting task runs, really.<commit_after>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # noqa pylint: disable=unused-import, redefined-builtin

import logging

from flexget import plugin
from flexget.event import event
from flexget.utils.template import get_template


log = logging.getLogger('notify_task')


class NotifyTask(object):
    schema = {
        'type': 'object',
        'properties': {
            'title': {
                'type': 'string',
                'default': '[FlexGet] {{task.name}}:'
                           '{%if task.failed %} {{task.failed|length}} failed entries.{% endif %}'
                           '{% if task.accepted %} {{task.accepted|length}} new entries downloaded.{% endif %}'},
            'template': {'type': 'string', 'default': 'default.template'},
            'to': {
                'type': 'array', 'items':
                    {'allOf': [
                        {'$ref': '/schema/plugins?group=notifiers'},
                        {'maxProperties': 1,
                         'error_maxProperties': 'Plugin options indented 2 more spaces than the first letter of the'
                                                ' plugin name.',
                         'minProperties': 1}]}}

        },
        'required': ['to']
    }

    def on_task_notify(self, task, config):
        if not (task.accepted or task.failed):
            log.verbose('No accepted or failed entries, not sending a notification.')
            return
        plugin.get_plugin_by_name('notify').instance.send_notification(config['title'],
                                                                       get_template(config['template'], 'task'),
                                                                       template_renderer=task.render)


@event('plugin.register')
def register_plugin():
    plugin.register(NotifyTask, 'notify_task', api_ver=2)
{'fraction_non_alphanumeric': 0.12300154718927282, 'fraction_numerical': 0.0020629190304280558, 'mean_word_length': 1.7608540925266905, '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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4541443', 'n_tokens_mistral': 958, 'n_tokens_neox': 911, 'n_words': 238}