<commit_before>'''
Used to send messages to a specified Slack channel. 
Set the token and channel in the config.ini file in the /slack folder

Install Slack Developer Kit for Python
http://slackapi.github.io/python-slackclient/

Usage:
from notify.slack import send_slack

send_slack.notify(project_code, "Your message here")

'''

from slackclient import SlackClient
import os.path as op
import configparser

def fetch_config(prj_number):
    config = configparser.ConfigParser()
    ini_file = op.join(op.dirname(op.abspath(__file__)), "config.ini")
    if op.exists(ini_file):
        config.read(ini_file)
        if prj_number in config:
            token = config[prj_number]["token"]
            channel = config[prj_number]["channel"]
            return token, channel 
    else:
        return None, None

def notify(prj_number, msg):
    slack_token, slack_channel = fetch_config(prj_number)

    sc = SlackClient(slack_token)
    
    sc.api_call(
        "chat.postMessage",
        channel=slack_channel,
        text=msg,
        username="rvt_model_services",
        #placeholder icon
        icon_url="http://lorempixel.com/48/48/"
    )<commit_msg>notify/slack send_slack - adjusted notify() so it is similar to email<commit_after>"""
Used to send messages to a specified Slack channel. 
Set the token and channel in the config.ini file in the /slack folder

Install Slack Developer Kit for Python
http://slackapi.github.io/python-slackclient/

Usage:
from notify.slack import send_slack

send_slack.notify(project_code, "Your message here")
"""

from slackclient import SlackClient
import os.path as op
import configparser


def fetch_config(prj_number):
    config = configparser.ConfigParser()
    ini_file = op.join(op.dirname(op.abspath(__file__)), "config.ini")
    if op.exists(ini_file):
        config.read(ini_file)
        if prj_number in config:
            token = config[prj_number]["token"]
            channel = config[prj_number]["channel"]
            return token, channel 
    else:
        return None, None


def notify(prj_number, prj_path, msg):
    slack_token, slack_channel = fetch_config(prj_number)

    sc = SlackClient(slack_token)

    notify_text = f"warning - rvt model {prj_number} at path {prj_path} is corrupt! \nsee journal: {msg}"
    
    sc.api_call(
                "chat.postMessage",
                channel=slack_channel,
                text=notify_text,
                username="rvt_model_services",
                # placeholder icon
                icon_url="http://lorempixel.com/48/48/"
                )
{'fraction_non_alphanumeric': 0.09398058252427184, 'fraction_numerical': 0.0031067961165048546, 'mean_word_length': 2.9148936170212765, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6784418', 'n_tokens_mistral': 814, 'n_tokens_neox': 786, 'n_words': 203}