Example #1
0
def makestats(objs, target, skip=[]):
    stats = StatDict()
    if not objs: return stats
    ignore = []
    res = []
    count = {}
    for t in target:
        for u in objs:
            if u in ignore: continue
            if u and u.data and u.data.txt:
                cont = False
                for s in skip:
                    if s in u.data.url: cont = True ; break
                if cont: continue
                if t in u.data.txt:
                    res.append(u)
                else:
                    ignore.append(u)
                    try: res.remove(u)
                    except ValueError: pass 
    for item in res:
        c = 0
        if not item in ignore:
            for t in target: c += item.data.txt.count(t)
            stats.upitem(item.data.url, c)
    return stats
Example #2
0
def handle_karmawhodown(bot, event):
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    sd = StatDict(item.data.whodown)
    res = []
    for i in sd.down():
        res.append("%s: %s" % i)
    if res: event.reply("downers of %s are: " % k, res)
    else: event.reply("nobody downed %s yet" % k)
Example #3
0
def handle_karmawhoup(bot, event):
    """ arguments: <item> - show who increased the karma of an item. """
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    sd = StatDict(item.data.whoup)
    res = []
    for i in sd.top():
        res.append("%s: %s" % i)
    if res: event.reply("uppers of %s are: " % k, res)
    else: event.reply("nobody upped %s yet" % k)
Example #4
0
 def input(self, html):
     self.scantime = time.time()
     words = striphtml(html)
     words = words.replace("\n", "").split()
     stats = StatDict()
     for w in words:
         stats.upitem(w)
     self.data.url = self.url.url
     self.data.words = stats
     self.save()
     logging.warn("%s words found for %s" % (len(stats), self.url.url))
     return stats
Example #5
0
 def quotebad(self, limit=10):
     """ show lowest 10 of negative karma items """
     global db
     if not db:
         logging.error("plugin isnt initialised yet")
         return []
     statdict = StatDict()
     result = db.execute(""" SELECT item, value FROM karma """)
     if not result: return []
     for i in result:
         if not i[0].startswith('quote '): continue
         statdict.upitem(i[0], value=i[1])
     return statdict.down(limit=limit)
Example #6
0
def handle_chatlogstats(bot, event):
    """ no arguments - create log stats of the channel, possible options: --chan <channel> """
    what = event.rest.strip()
    chatlogdir = getdatadir() + os.sep + "chatlogs"
    if event.options and event.options.channel: chan = event.options.channel
    else: chan = event.channel
    logs = os.listdir(chatlogdir)
    if not logs: event.reply("no logs available for %s" % chan) ; return
    now = time.time()
    if what: timetarget = strtotime2(what) ; what = striptime(what)
    else: timetarget = 0 ; what = None
    event.reply("creating stats for channel %s (%s)" % (chan, time.ctime(timetarget)))
    userstats = StatDict()
    wordstats = StatDict()
    stop = False
    for f in logs[::-1]:
        filename = stripname(f)
        channel = stripname(chan[1:])
        if not channel in filename: continue
        for line in open(chatlogdir + os.sep + filename, 'r'):
            splitted = line.strip().split()
            if len(splitted) < 2: continue
            who = "unknown"
            for i in splitted:
               if i.startswith("<"): who = i[1:-1]
            if what and who != what: continue
            timestr = "%s %s" % (splitted[0], splitted[1])
            logtime = strtotime2(timestr)
            if logtime:
                if logtime > timetarget: userstats.upitem(who)
                else: continue
            else: userstats.upitem(who)
            for word in splitted[4:]: wordstats.upitem(word)
    if what: result = wordstats.top()
    else: result = userstats.top()
    if result:
        res = ["%s: %s" % item for item in result]
        event.reply("stat results for %s: " % (what or chan), res)
    else: event.reply("no result found for %s" % (what or chan))
Example #7
0
def handle_karmagood(bot, event):
    """ arguments: none - show top karma items of a channel. """
    collection = PlugPersistCollection()
    stats = StatDict()
    objs = collection.objects(event.channel.lower())
    for name, obj in objs.iteritems():
       if not obj.data: logging.warn("%s is empty" % name) ; continue
       item = stripname(name).split("-")[-1]
       stats.upitem(item, obj.data.count)
    res = []
    for item in stats.top():
        res.append("%s - %s" % item)
    event.reply("top karma items of %s: " % event.channel, res)
Example #8
0
def handle_karmawhoup(bot, event):
    """ arguments: <item> - show who increased the karma of an item. """
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    sd = StatDict(item.data.whoup)
    #    res = []
    #    for i in sorted(sd.top(),key=itemgetter(1), reverse=True):
    #        res.append("%s: %s" % i)
    res = ""
    for item in sorted(sd.top(), key=itemgetter(1), reverse=True):
        res += (str(item[0]) + ':' + str(item[1]) + ' ')
    if res: event.reply("uppers of " + k + " are: " + res)
    else: event.reply("nobody upped " + k + " yet")
Example #9
0
def handle_stats(bot, event):
    totalstats = StatDict()
    counter = 0
    for modname in sys.modules:
        if modname.startswith("jsb"):
            plugname = modname.split(".")[-1]
            if event.args and plugname not in event.args: continue
            try:
                modstats = getattr(sys.modules[modname], "stats")
            except AttributeError:
                continue
            totalstats += modstats
            counter += 1
    event.reply("stats results from %s modules: " % counter, totalstats)
Example #10
0
 def whatup(self, nick):
     """ show what items are upped by nick """
     global db
     if not db:
         logging.error("plugin isnt initialised yet")
         return []
     nick = nick.lower()
     statdict = StatDict()
     result = db.execute(
         """ SELECT item FROM whokarma WHERE nick = %s AND updown = 'up' """,
         nick)
     if not result: return []
     for i in result:
         statdict.upitem(i[0])
     return statdict.top()
Example #11
0
def handle_threads(bot, ievent):
    """ no arguments - show running threads. """
    try:
        import threading
    except ImportError:
        ievent.reply("threading is not enabled.")
        return
    stats = StatDict()
    threadlist = threading.enumerate()
    for thread in threadlist:
        stats.upitem(thread.getName())
    result = []
    for item in stats.top():
        result.append("%s = %s" % (item[0], item[1]))
    result.sort()
    ievent.reply("threads running: ", result)
Example #12
0
def handle_whokarmadown(bot, ievent):
    """ karma-whodown <item> .. show who decreased a karma item """
    if not ievent.rest:
        ievent.missing('<item>')
        return
    item = ievent.rest
    result = karma.getwhodown(item)
    statdict = StatDict()
    if result:
        for i in result:
            statdict.upitem(i)
        res = []
        for i in statdict.top():
            res.append("%s=%s" % i)
        ievent.reply("whokarmadown of %s: " % item, res)
    else:
        ievent.reply('no whokarmadown data available for %s' % item)
Example #13
0
def handle_karmagood(bot, event):
    """ arguments: none - show top karma items of a channel. """
    collection = PlugPersistCollection()
    #    event.reply('Processing karma list.')
    stats = StatDict()
    objs = collection.objects()
    for name, obj in objs.iteritems():
        if not obj.data:
            logging.warn("%s is empty" % name)
            continue
        item = stripname(name).split("-", 2)[-1]
        if stripname(name).split("-", 2)[1] == event.channel.lower()[1:]:
            stats.upitem(item, obj.data.count)
    ktop = stats.top(limit=20)
    #    event.reply(str(ktop))
    res = ""
    for item in ktop:
        res += (str(item[0]) + ':' + str(item[1]) + ' ')
    event.reply('Top 20 Karma for ' + event.channel + ': ' + res)
Example #14
0
from jsb.lib.errors import URLNotEnabled
from jsb.utils.statdict import StatDict
from jsb.utils.locking import lockdec

## basic imports

import Queue
import time
import thread
import random
import logging
import sys

## defines

stats = StatDict()

## locks

startlock = thread.allocate_lock()
startlocked = lockdec(startlock)

## Runner class


class Runner(RunnerLoop):
    """
        a runner is a thread with a queue on which jobs can be pushed. 
        jobs scheduled should not take too long since only one job can 
        be executed in a Runner at the same time.
Example #15
0
 def __init__(self):
     self.stats = StatDict()
     self.times = LazyDict()
     self.wait = LazyDict()
     self.warned = LazyDict()
Example #16
0
 def stats(self):
     stats = StatDict(self.data.words)
     return stats