<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json

import requests

from .base import BaseChannel
from channels.exceptions import HttpError, ImproperlyConfigured


class SlackChannel(BaseChannel):
    def __init__(self, config):
        # Required
        self.load_required_config(config, {
            "URL": "url"
        })

        # Optional
        self.load_optional_config(config, {
            "USERNAME": "username",
            "CHANNEL": "channel",
            "ICON_EMOJI": "icon_emoji",
            "ICON_URL": "icon_url"
        })

        # Validation
        if hasattr(self, "icon_emoji") and hasattr(self, "icon_url"):
            raise ImproperlyConfigured(
                "Must not set both ICON_EMOJI and ICON_URL")

    def send(self, message, fail_silently=False, options=None):
        payload = {
            'text': message
        }
        if hasattr(self, "channel"):
            payload["channel"] = self.channel
        if hasattr(self, "username"):
            payload["username"] = self.username
        if hasattr(self, "icon_url"):
            payload["icon_url"] = self.icon_url
        if hasattr(self, "icon_emoji"):
            payload["icon_emoji"] = self.icon_emoji
        data = {
            'payload': json.dumps(payload)
        }
        try:
            response = requests.post(self.url, data=data)
            if response.status_code != 200:
                raise HttpError(response.status_code)
        except:
            if not fail_silently:
                raise<commit_msg>Update SlackChannel<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json

import requests

from .base import BaseChannel
from channels.exceptions import HttpError, ImproperlyConfigured


class SlackChannel(BaseChannel):
    def __init__(self, config):
        # Required
        self.load_required_config(config, {
            "URL": "url"
        })

        # Optional
        self.load_optional_config(config, {
            "USERNAME": "username",
            "CHANNEL": "channel",
            "ICON_EMOJI": "icon_emoji",
            "ICON_URL": "icon_url"
        })

        # Validation
        if hasattr(self, "icon_emoji") and hasattr(self, "icon_url"):
            raise ImproperlyConfigured(
                "Must not set both ICON_EMOJI and ICON_URL")

    def send(self, message, fail_silently=False, options=None):
        payload = {
            'text': message
        }
        if hasattr(self, "channel"):
            payload["channel"] = self.channel
        if hasattr(self, "username"):
            payload["username"] = self.username
        if hasattr(self, "icon_url"):
            payload["icon_url"] = self.icon_url
        if hasattr(self, "icon_emoji"):
            payload["icon_emoji"] = self.icon_emoji
        data = {
            'payload': json.dumps(payload)
        }
        try:
            response = requests.post(self.url, data=data)
            if response.status_code != requests.codes.ok:
                raise HttpError(response.status_code)
        except:
            if not fail_silently:
                raise
{'fraction_non_alphanumeric': 0.10669191919191919, 'fraction_numerical': 0.0015782828282828283, 'mean_word_length': 2.006641366223909, 'pattern_counts': {'":': 10, '<': 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': '3364688', 'n_tokens_mistral': 911, 'n_tokens_neox': 899, 'n_words': 200}