<commit_before>from . import util
import asyncio
import logging
import os.path
import urllib.request
import hashlib
import json
from time import time

from slackclient import SlackClient

logger = logging.getLogger(__name__)

class SlackGateway:

    def __init__(self):
        self.IMGDIR = "/home/hangups/icons"
        self.IMGURL = "http://davr.org/slackicons"

        self.loadConfig()

    def loadConfig(self):
        config = os.path.expanduser("~/.slangouts/config.json")
        if not os.path.isfile(config):
            logging.critical("ERROR config file missing")
            return

        with fp = open(config):
            data = json.load(fp)

        self.token = data['slackApiToken']

    def connect(self):
        self.client = SlackClient(self.token)
        if self.client.rtm_connect():
            logger.info("Connected to Slack!")
        else:
            logger.critical("ERROR CONNCTING TO SLACK check token?")

    @asyncio.coroutine
    def run(self):
        logger.info("Starting slack event loop")
        yield from asyncio.sleep(0.1)
        for channel in self.client.server.channels:
            n = str(channel.name)
            i = str(channel.id)
            logger.info("Slack Channel: "+n+" ["+i+"]")
        yield from asyncio.sleep(0.1)
        while True:
            for event in self.client.rtm_read():
                et = event['type']
                if et == 'message':
                    logger.info(json.dumps(event).encode('utf-8'))

                    # normal messages have no subtype
                    if not 'subtype' in event:
                        # reply_to is a response from server telling us they got the msg, ignore it
                        if not 'reply_to' in event:
                           logger.info("Send msg")

            yield from asyncio.sleep(0.1)<commit_msg>Working on group autodetection<commit_after>from . import util
import asyncio
import logging
import os.path
import urllib.request
import hashlib
import json
from time import time

from slackclient import SlackClient

logger = logging.getLogger(__name__)

class SlackGateway:

    def __init__(self):
        self.IMGDIR = "/home/hangups/icons"
        self.IMGURL = "http://davr.org/slackicons"

        self.loadConfig()

    def loadConfig(self):
        config = os.path.expanduser("~/.slangouts/config.json")
        if not os.path.isfile(config):
            logging.critical("ERROR config file missing")
            return

        with fp = open(config):
            data = json.load(fp)

        self.token = data['slackApiToken']

    def connect(self):
        self.client = SlackClient(self.token)
        if self.client.rtm_connect():
            logger.info("Connected to Slack!")
        else:
            logger.critical("ERROR CONNCTING TO SLACK check token?")

    def addGroup(self, group):
        self.groups[group['id']] = group
        purpose = group['purpose']['value']
        if purpose[0:17] == 'Hangouts Bridge: ':
            hangoutid = purpose[17:]
            self.grouphash[hangoutid] = group['id']

    @asyncio.coroutine
    def run(self):
        logger.info("Starting slack event loop")
        yield from asyncio.sleep(0.1)
        logger.info("Requesting slack groups")
        res = self.client.api_call('groups.list', exclude_archived=1)
        self.groups = dict()
        self.grouphash = dict()
        if 'ok' in res and res['ok']:
            for group in res.groups:
                addGroup(group)
        else:
            logger.critical("ERROR LISTING SLACK GROUPS check token?")
            logger.critical(json.dumps(res).encode("utf-8"))

        yield from asyncio.sleep(0.1)
        while True:
            for event in self.client.rtm_read():
                et = event['type']
                if et == 'message':
                    logger.info(json.dumps(event).encode('utf-8'))

                    # normal messages have no subtype
                    if not 'subtype' in event:
                        # reply_to is a response from server telling us they got the msg, ignore it
                        if not 'reply_to' in event:
                           logger.info("Send msg")

            yield from asyncio.sleep(0.1)
{'fraction_non_alphanumeric': 0.10537482319660538, 'fraction_numerical': 0.0049504950495049506, 'mean_word_length': 1.9241902136457616, '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': '85471', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1177, 'n_words': 314}