<commit_before># -*- coding: utf-8 -*-

import re
from urllib import urlencode
import urllib2
from datetime import date
from datetime import datetime
from twisted.words.xish import domish
import htmlentitydefs
from shoutbox import *
from utilities import *
import xml.parsers.expat

class MessageShoutbox(Shoutbox):
    latest_shout = 0
    first_shout = 0
    base_url = ""

    def __init__(self, config):
        self.parser = ElementParser()
        self.cfg = config
        self.base_url = config.base_url

    def __del__(self):
        pass

    def readShouts(self, start=-1):
        """
        Read shoutbox messages, all or newer than "start".
        """
        if start < 0:
            start = self.latest_shout
        print "Loading shouts, with start:", start
        shoutdata = self.loadShouts(start)
        shouts = self.parseShouts(shoutdata)
        return shouts

    def loadShouts(self, start):
        params = urlencode({
            "ubb": "listshouts",
            "shout": start,
        })
        shoutxml = loadUrl(self.base_url, params)
        return shoutxml

    def parseShout(self, s):
        return Shout(s['id'], s['from_id'], s['from'], self._getElStr(s.body), s['time'])

    def sendShout(self, user, message):
        params = urlencode({
            "ubb": "listshouts",
            "action": "send",
            "secret": self.cfg.secret,
            "user_id": user.id,
            "user_name": user.name,
            "message": message.encode('latin-1', 'xmlcharrefreplace'),
        })
        result = loadUrl(self.base_url, params)<commit_msg>Oops, had encoded to latin1 instead of utf8, my bad.<commit_after># -*- coding: utf-8 -*-

import re
from urllib import urlencode
import urllib2
from datetime import date
from datetime import datetime
from twisted.words.xish import domish
import htmlentitydefs
from shoutbox import *
from utilities import *
import xml.parsers.expat

class MessageShoutbox(Shoutbox):
    latest_shout = 0
    first_shout = 0
    base_url = ""

    def __init__(self, config):
        self.parser = ElementParser()
        self.cfg = config
        self.base_url = config.base_url

    def __del__(self):
        pass

    def readShouts(self, start=-1):
        """
        Read shoutbox messages, all or newer than "start".
        """
        if start < 0:
            start = self.latest_shout
        print "Loading shouts, with start:", start
        shoutdata = self.loadShouts(start)
        shouts = self.parseShouts(shoutdata)
        return shouts

    def loadShouts(self, start):
        params = urlencode({
            "ubb": "listshouts",
            "shout": start,
        })
        shoutxml = loadUrl(self.base_url, params)
        return shoutxml

    def parseShout(self, s):
        return Shout(s['id'], s['from_id'], s['from'], self._getElStr(s.body), s['time'])

    def sendShout(self, user, message):
        params = urlencode({
            "ubb": "listshouts",
            "action": "send",
            "secret": self.cfg.secret,
            "user_id": user.id,
            "user_name": user.name,
            "message": message.encode('utf-8', 'xmlcharrefreplace'),
        })
        result = loadUrl(self.base_url, params)
{'fraction_non_alphanumeric': 0.1152301513747297, 'fraction_numerical': 0.004942848316342292, 'mean_word_length': 2.2873096446700507, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '4695163', 'n_tokens_mistral': 989, 'n_tokens_neox': 967, 'n_words': 258}