<commit_before># -*- coding: utf-8 -*-
import json
import StringIO
import urllib

from bleach import clean
from twisted.internet import reactor
from twisted.web.client import Agent, FileBodyProducer, readBody
from twisted.web.http_headers import Headers

from config import SLACK_NOTI_CHANNEL, SLACK_POST_INFO, SLACK_NOTI_TARGET_BOARDS, logger

SLACK_CHAT_POST_MESSAGE_URL = "https://slack.com/api/chat.postMessage"

agent = Agent(reactor)

def post_message(request, article, article_view_url):
    if article.board.repr not in SLACK_NOTI_TARGET_BOARDS:
        return
    article_link = request.getProto() + "://" + request.getHost() + article_view_url
    content = clean(article.compiled_content, tags=[], strip=True)
    if len(content) > 30:
        content = content[:27] + "..."
    params = {
        "text": u"%s에 새 글이 등록되었습니다." % article.board.repr,
        "channel": SLACK_NOTI_CHANNEL,
    }
    params.update(SLACK_POST_INFO)
    attachments = list()
    attachments.append({
        "title": article.subject,
        "title_link": article_link,
        "text": content,
        "author_name": article.author.nickname,
    })
    params["attachments"] = json.dumps(attachments)
    body = FileBodyProducer(StringIO.StringIO(urllib.urlencode(params)))

    d = agent.request(
        "POST",
        "https://slack.com/api/chat.postMessage",
        Headers({"User-Agent": ["Twisted Web Server Slack Notify"]}),
        body
    )
    d.addBoth(slack_callback)

def slack_callback(resp):
        d = readBody(resp)
        d.addCallback(slack_resp)

def slack_resp(resp_body):
    response = json.loads(resp_body)
    if not response["ok"]:
        logger.error("Slack post message error : %s", response["error"])<commit_msg>import error fix<commit_after># -*- coding: utf-8 -*-
import json
import StringIO
import urllib

from bleach import clean
from twisted.internet import reactor
from twisted.web.client import Agent, FileBodyProducer, readBody
from twisted.web.http_headers import Headers

from config.config import SLACK_NOTI_CHANNEL, SLACK_POST_INFO, SLACK_NOTI_TARGET_BOARDS

SLACK_CHAT_POST_MESSAGE_URL = "https://slack.com/api/chat.postMessage"

agent = Agent(reactor)

def post_message(request, article, article_view_url):
    if article.board.repr not in SLACK_NOTI_TARGET_BOARDS:
        return
    article_link = request.getProto() + "://" + request.getHost() + article_view_url
    content = clean(article.compiled_content, tags=[], strip=True)
    if len(content) > 30:
        content = content[:27] + "..."
    params = {
        "text": u"%s에 새 글이 등록되었습니다." % article.board.repr,
        "channel": SLACK_NOTI_CHANNEL,
    }
    params.update(SLACK_POST_INFO)
    attachments = list()
    attachments.append({
        "title": article.subject,
        "title_link": article_link,
        "text": content,
        "author_name": article.author.nickname,
    })
    params["attachments"] = json.dumps(attachments)
    body = FileBodyProducer(StringIO.StringIO(urllib.urlencode(params)))

    d = agent.request(
        "POST",
        "https://slack.com/api/chat.postMessage",
        Headers({"User-Agent": ["Twisted Web Server Slack Notify"]}),
        body
    )
    d.addBoth(slack_callback, request)

def slack_callback(resp, request):
        d = readBody(resp)
        d.addCallback(slack_resp, request)

def slack_resp(resp_body, request):
    response = json.loads(resp_body)
    if not response["ok"]:
        request.logger.error("Slack post message error : %s", response["error"])
{'fraction_non_alphanumeric': 0.12237365133446905, 'fraction_numerical': 0.0028392958546280523, 'mean_word_length': 3.5051150895140664, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '7412145', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1160, 'n_words': 236}