<commit_before>#!/usr/bin/env python

import os
import yaml
import re


class ChannelFilter(object):
    def __init__(self, path=None):
        if path is None:
            path = os.path.join(os.path.dirname(__file__), 'channels.yaml')
        with open(path) as f:
            self.config = yaml.load(f)

        self.parse_regexps()
        print(self.config)

    def parse_regexps(self):
        chan_proj_map = self.config['channels']
        for channel in chan_proj_map:
            fullregex = "^(" + "|".join(chan_proj_map[channel]) + ")$"
            chan_proj_map[channel] = re.compile(fullregex)

    @property
    def firehose_channel(self):
        return self.config['firehose-channel']

    @property
    def default_channel(self):
        return self.config['default-channel']

    def all_channels(self):
        channels = [self.default_channel, self.firehose_channel] + list(self.config['channels'])
        return list(set(channels))

    def channels_for(self, projects):
        """
        :param project: Get all channels to spam for given projects
        :type project: list
        """
        channels = set()
        for channel in self.config['channels']:
            for project in projects:
                if self.config['channels'][channel].match(project):
                    channels.add(channel)
                    break<commit_msg>make channel filter case-insensitive<commit_after>#!/usr/bin/env python

import os
import yaml
import re


class ChannelFilter(object):
    def __init__(self, path=None):
        if path is None:
            path = os.path.join(os.path.dirname(__file__), 'channels.yaml')
        with open(path) as f:
            self.config = yaml.load(f)

        self.parse_regexps()
        print(self.config)

    def parse_regexps(self):
        chan_proj_map = self.config['channels']
        for channel in chan_proj_map:
            fullregex = "^(" + "|".join(chan_proj_map[channel]) + ")$"
            chan_proj_map[channel] = re.compile(fullregex,
                    flags=(re.IGNORECASE | re.UNICODE)
            )

    @property
    def firehose_channel(self):
        return self.config['firehose-channel']

    @property
    def default_channel(self):
        return self.config['default-channel']

    def all_channels(self):
        channels = [self.default_channel, self.firehose_channel] + list(self.config['channels'])
        return list(set(channels))

    def channels_for(self, projects):
        """
        :param project: Get all channels to spam for given projects
        :type project: list
        """
        channels = set()
        for channel in self.config['channels']:
            for project in projects:
                if self.config['channels'][channel].match(project):
                    channels.add(channel)
                    break
{'fraction_non_alphanumeric': 0.11424541607898449, 'fraction_numerical': 0.0, 'mean_word_length': 2.2722029988465975, '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': '3692514', 'n_tokens_mistral': 835, 'n_tokens_neox': 790, 'n_words': 180}