<commit_before>import logging

from core.channel import (Channel, NotSupportedTrigger, NotSupportedAction,
                          ConditionNotMet, ChannelStateForUser)
from core.utils import replace_text_mappings
from core.models import (RecipeCondition, Recipe, TriggerInput)
from channel_rss.config import TRIGGER_TYPE


class RssChannel(Channel):

    def handle_action(self, action_type, userid, inputs):
        """
        The RSS channel does not support any actions at the moment.

        Raises:
            NotSupportedAction
        """
        raise NotSupportedAction("The RSS channel does not support actions.")

    def fill_recipe_mappings(self, trigger_type, userid,
                             payload, conditions, mappings):
        if payload['feed_url'] != conditions['feed_url']:
            raise ConditionNotMet('Feed urls do not match.')
        # check for trigger type and replace mappings accordingly
        if trigger_type == TRIGGER_TYPE['new_entries']:
            to_replace = ['summaries', 'summaries_and_links']
            return replace_text_mappings(mappings=mappings,
                                         to_replace=to_replace,
                                         payload=payload)
        else:
            raise NotSupportedTrigger('trigger_type {} not supported'.format(
                trigger_type))

    def user_is_connected(self, user):
        """
        Always returns unnecessary.
        """
        return ChannelStateForUser.unnecessary

    def fetch_entries_by_keyword(self, feed):
        """

        Args:
            feed:

        Returns:

        """

        '''
        get all recipe conditions of a recipe that have the feed url as a
        recipe condition and that correspond to the trigger input keyword.
        These recipe conditions are the keywords that condition if a
        certain recipe is triggered and executed.
        '''
        trigger_type = TRIGGER_TYPE['entries_keyword']
        url_input = TriggerInput.objects.get(trigger__channel__name='RSS',
                                             trigger__trigger_type=trigger_type,
                                             name='feed_url')
        keyword_input = TriggerInput.objects.get(
                trigger__channel__name='RSS',
                trigger__trigger_type=trigger_type,
                name='keyword')
        # get all conditions of the feeds url
        url_conditions = RecipeCondition.objects.filter(value=feed.url,
                                                        trigger_input=url_input)

        for condition in url_conditions:
            # for each condition get the corresponding recipe
            # then get the keyword and check for occurrence
            keyword_cond = RecipeCondition.objects.get(
                    recipe=condition.recipe,
                    trigger_input=keyword_input)
            # TODO check 









<commit_msg>get keywords<commit_after>import logging

from core.channel import (Channel, NotSupportedTrigger, NotSupportedAction,
                          ConditionNotMet, ChannelStateForUser)
from core.utils import replace_text_mappings
from core.models import (RecipeCondition, Recipe, TriggerInput)
from channel_rss.config import TRIGGER_TYPE


class RssChannel(Channel):

    def handle_action(self, action_type, userid, inputs):
        """
        The RSS channel does not support any actions at the moment.

        Raises:
            NotSupportedAction
        """
        raise NotSupportedAction("The RSS channel does not support actions.")

    def fill_recipe_mappings(self, trigger_type, userid,
                             payload, conditions, mappings):
        if payload['feed_url'] != conditions['feed_url']:
            raise ConditionNotMet('Feed urls do not match.')
        # check for trigger type and replace mappings accordingly
        if trigger_type == TRIGGER_TYPE['new_entries']:
            to_replace = ['summaries', 'summaries_and_links']
            return replace_text_mappings(mappings=mappings,
                                         to_replace=to_replace,
                                         payload=payload)
        else:
            raise NotSupportedTrigger('trigger_type {} not supported'.format(
                trigger_type))

    def user_is_connected(self, user):
        """
        Always returns unnecessary.
        """
        return ChannelStateForUser.unnecessary

    def fetch_entries_by_keyword(self, feed):
        """

        Args:
            feed:

        Returns:

        """

        '''
        get all recipe conditions of a recipe that have the feed url as a
        recipe condition and that correspond to the trigger input keyword.
        These recipe conditions are the keywords that condition if a
        certain recipe is triggered and executed.
        '''
        trigger_type = TRIGGER_TYPE['entries_keyword']
        url_input = TriggerInput.objects.get(trigger__channel__name='RSS',
                                             trigger__trigger_type=trigger_type,
                                             name='feed_url')
        keyword_input = TriggerInput.objects.get(
                trigger__channel__name='RSS',
                trigger__trigger_type=trigger_type,
                name='keyword')
        # get all conditions of the feeds url
        url_conditions = RecipeCondition.objects.filter(value=feed.url,
                                                        trigger_input=url_input)
        # TODO: fetch rss feed

        for condition in url_conditions:
            # for each condition get the keyword via the corresponding recipe
            keyword_cond = RecipeCondition.objects.get(
                    recipe=condition.recipe,
                    trigger_input=keyword_input)
            # TODO check for occurence / get the entries
            # TODO build strings, fill payoad
            # TODO fire trigger










{'fraction_non_alphanumeric': 0.06290890790135883, 'fraction_numerical': 0.0, 'mean_word_length': 1.8871670702179177, '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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5810595', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1337, 'n_words': 397}