<commit_before>from __future__ import unicode_literals, division, absolute_import
import logging
from flexget import plugin
from flexget.entry import Entry
from flexget.event import event
from flexget.utils.charts_snep import SnepChartsParser, SnepParsedChartEntry
from flexget.utils.cached_input import cached

log = logging.getLogger('charts_snep_input')


source_enum = ['all_album', 'disk_album', 'digit_album',
               'digit_single', 'stream_single',
               'compil', 'back_catalog', 'radio']

class ChartsSnepInput(object):
    """Create an entrie for each charted single in your charts request"""

    schema = {
        'type': 'string'
    }


    @cached('charts_snep_input', persist='2 hours')
    def on_task_input(self, task, config):
        if config not in source_enum:
            log.warning("'%s' is an unknow charts type for charts_snep. Please to use %s."
                        % (config, ', '.join(source_enum)))
            return []


        log.verbose('Retrieving weekly SNEP charts of %s' % config)
        parser = SnepChartsParser()
        chart_entries = parser.retrieve_charts(config)
        """:type chart_entries: list of [flexget.utils.charts_snep.SnepParsedChartEntry]"""

        input_entries = []
        for charts_entry in chart_entries:
            flexget_entry = Entry()
            flexget_entry['title'] = "%s - %s" % (charts_entry.artist, charts_entry.recording_title)
            flexget_entry.update_using_map(SnepParsedChartEntry.get_entry_map(), charts_entry)
            input_entries.append(flexget_entry)

        return input_entries

@event('plugin.register')
def register_plugin():<commit_msg>PEP8 and docs<commit_after>from __future__ import unicode_literals, division, absolute_import
import logging
from flexget import plugin
from flexget.entry import Entry
from flexget.event import event
from flexget.utils.charts_snep import SnepChartsParser, SnepParsedChartEntry
from flexget.utils.cached_input import cached

log = logging.getLogger('charts_snep_input')

source_enum = ['all_album', 'disk_album', 'digit_album',
               'digit_single', 'stream_single',
               'compil', 'back_catalog', 'radio']


def valid_config(config):
    return config not in source_enum


# TODO: Use db for improved perfs?
class ChartsSnepInput(object):
    """
    Create an entrie for each charted single in your charts request.

    Syntax:
    charts_snep_input: <one of : ['all_album', 'disk_album', 'digit_album',
               'digit_single', 'stream_single',
               'compil', 'back_catalog', 'radio']>
    """
    schema = {
        'type': 'string'
    }


    @cached('charts_snep_input', persist='2 hours')
    def on_task_input(self, task, config):
        # Check config
        if not valid_config(config):
            log.warning("'%s' is an unknow charts type for charts_snep. Please to use one of them : %s."
                        % (config, ', '.join(source_enum)))
            return []

        # Charts retrieving
        log.verbose('Retrieving weekly SNEP charts of %s' % config)
        parser = SnepChartsParser()
        chart_entries = parser.retrieve_charts(config)
        """:type chart_entries: list of [flexget.utils.charts_snep.SnepParsedChartEntry]"""

        # Build/map the result
        input_entries = []
        for charts_entry in chart_entries:
            flexget_entry = Entry()
            flexget_entry['title'] = "%s - %s" % (charts_entry.artist, charts_entry.recording_title)
            flexget_entry.update_using_map(SnepParsedChartEntry.get_entry_map(), charts_entry)
            input_entries.append(flexget_entry)

        return input_entries


@event('plugin.register')
def register_plugin():
{'fraction_non_alphanumeric': 0.10179480310742031, 'fraction_numerical': 0.0008036431824270024, 'mean_word_length': 3.1581291759465477, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, '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': '2223171', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1083, 'n_words': 272}