<commit_before>"""client.py - client for wikitweets"""
import os
import re
import sys
import random
import getopt
import logging
import logging.config
import ConfigParser

import twitter # pip install python-twitter
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol
from twisted.python import log as twisted_log

from . import config

TWEET = logging.INFO + 1
logging.addLevelName(logging.INFO + 1, 'TWEET')
log = logging.getLogger(__name__)

def shorter(item):
    """Make a string shorter.

    item -- a unicode string."""
    if len(item > 2):
        return item[:-2] + u'\u2026' # ellipsis
    return item

class EditsListener(irc.IRCClient):
    """IRC bot that listens to wikipedia edits."""
    # edit message looks like this:
    # u'\x0314[[\x0307Darin Erstad\x0314]]\x034 \x0310 \x0302http://en.wikipedia.org/w/index.php?diff=650841539&oldid=650491223\x03 \x035*\x03 \x0303Erik255\x03 \x035*\x03 (+2) \x0310\x03'
    edit_re = re.compile(
        r'^\x0314\[\[\x0307'    # <grey>[[<yellow>
        r'([^\x03]*)'           # Article name
        r'\x0314\]\]'           # <grey>]]
        r'\x034 \x0310 \x0302'  # <?><?><blue>
        r'([^\x03]*)'           # Diff URI
        r'\x03 \x035\*\x03 \x0303' # <red><literal *><green>
        r'([^\x03]*)'           # User name or IP address
    )
    ip_re = re.compile(
        r'^([0-9]{1,3}\.){3}[0-9]{1,3}$') # TODO - IPv6

    def __init__(self, cfg, twitter_api):
        self.nickname = cfg.irc.nick
        self.articles = cfg.articles
        self.message_fmt = cfg.twitter.message_fmt
        self.twitter_api = twitter_api

    def connectionMade(self):
        irc.IRCClient.connectionMade(self)
        log.info("Connected to IRC")

    def connectionLost(self, reason):
        irc.IRCClient.connectionLost(self, reason)
        log.info("Disconnected from IRC")

    # callbacks for events

    def signedOn(self):
        """Called when bot has succesfully signed on to server."""
        log.info('Signed on to IRC')
        self.join(self.factory.channel)<commit_msg>Fix a bug where wikitweets would not rejoin the IRC channel.<commit_after>"""client.py - client for wikitweets"""
import os
import re
import sys
import random
import getopt
import logging
import logging.config
import ConfigParser

import twitter # pip install python-twitter
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol
from twisted.python import log as twisted_log

from . import config

TWEET = logging.INFO + 1
logging.addLevelName(logging.INFO + 1, 'TWEET')
log = logging.getLogger(__name__)

def shorter(item):
    """Make a string shorter.

    item -- a unicode string."""
    if len(item > 2):
        return item[:-2] + u'\u2026' # ellipsis
    return item

class EditsListener(irc.IRCClient):
    """IRC bot that listens to wikipedia edits."""
    # edit message looks like this:
    # u'\x0314[[\x0307Darin Erstad\x0314]]\x034 \x0310 \x0302http://en.wikipedia.org/w/index.php?diff=650841539&oldid=650491223\x03 \x035*\x03 \x0303Erik255\x03 \x035*\x03 (+2) \x0310\x03'
    edit_re = re.compile(
        r'^\x0314\[\[\x0307'    # <grey>[[<yellow>
        r'([^\x03]*)'           # Article name
        r'\x0314\]\]'           # <grey>]]
        r'\x034 \x0310 \x0302'  # <?><?><blue>
        r'([^\x03]*)'           # Diff URI
        r'\x03 \x035\*\x03 \x0303' # <red><literal *><green>
        r'([^\x03]*)'           # User name or IP address
    )
    ip_re = re.compile(
        r'^([0-9]{1,3}\.){3}[0-9]{1,3}$') # TODO - IPv6

    def __init__(self, cfg, twitter_api):
        self.nickname = cfg.irc.nick
        self.channel = cfg.irc.channel
        self.articles = cfg.articles
        self.message_fmt = cfg.twitter.message_fmt
        self.twitter_api = twitter_api

    def connectionMade(self):
        irc.IRCClient.connectionMade(self)
        log.info("Connected to IRC")

    def connectionLost(self, reason):
        irc.IRCClient.connectionLost(self, reason)
        log.info("Disconnected from IRC")

    # callbacks for events

    def signedOn(self):
        """Called when bot has succesfully signed on to server."""
        log.info('Signed on to IRC')
        log.info('Joining %s', self.channel)
        self.join(self.channel)
{'fraction_non_alphanumeric': 0.14182411943083742, 'fraction_numerical': 0.059248891999066945, 'mean_word_length': 2.6901893287435454, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '1418349', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1440, 'n_words': 354}