#!/usr/bin/python -tt # # SILAN # Simple IRC Log Analyzer # http://slackforge.com/silan/ # # Version 0.0.2 # An extremely simple IRC log analyzer --; # Only supports dircproxy logs, because that's what I use # # Copyright (c) 2007 Shidayu # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. ## ## # Import Other Modules # import os, re, stat, sys, glob, datetime, string, time, random ## # Class Definitions # class Silan(object): """ Simple IRC Log Analyzer """ def __init__(self): ## # Regular Expressions used by SILAN # self.re_rawlog = re.compile('^\[(\d\d) ([A-Z][a-z][a-z]) (\d\d):(\d\d)\] ([^\n\r\f\v]*)$') self.re_ownnick = re.compile('--- You changed your nickname to (\S*)') self.re_nickchange = re.compile('--- (\S*) \([^\t\n\r\f\v)]*\) changed nickname to (\S*)') self.re_quit = re.compile('<-- (\S*) \([^\t\n\r\f\v)]*\) quit from IRC: ([^\n\r\f\v]*)$') self.re_join = re.compile('--> (\S*) \([^\t\n\r\f\v)]*\) joined the channel$') self.re_part = re.compile('<-- (\S*) \([^\t\n\r\f\v)]*\) left the channel$') self.re_message = re.compile('<([^ \t\n\r\f\v!]*)![^\t\n\r\f\v>]*> ([^\n\r\f\v]*)$') self.re_describe = re.compile('\* (\S*) ([^\n\r\f\v]*)') self.re_topic = re.compile('--- (\S*) \([^\t\n\r\f\v)]*\) changed topic: ([^\t\n\r\f\v]*)$') self.re_kick = re.compile('<-- (\S*) kicked off by (\S*) \([^\t\n\r\f\v)]*\): ([^\n\r\f\v]*)$') self.re_ownkick = re.compile('<-- Kicked off by (\S*) \([^\t\n\r\f\v)]*\): ([^\n\r\f\v]*)$') self.re_nonword = re.compile('[^a-zA-Z0-9]*') self.re_channame = re.compile('^(\S*).log$') ### # Month conversion Dictionary # self.fmt_month = { "Jan": 1, "Feb": 2, "Mar": 3, "Apr": 4, "May": 5, "Jun": 6, "Jul": 7, "Aug": 8, "Sep": 9, "Oct": 10, "Nov": 11, "Dec": 12 } class Line(object): """ Line of log data with date and time """ def __init__(self, dttm, text): self.dttm = dttm self.text = text def wordcount(self): return len(self.text.split()) class UserLine(Line): """ Line of log data that includes user instance """ def __init__(self, dttm, user, text): Line.__init__(self, dttm, text) self.user = user class Message(UserLine): """ Standard IRC message from a user """ def __init__(self, dttm, user, text): UserLine.__init__(self, dttm, user, text) class Describe(UserLine): """ Describe or action from a user """ def __init__(self, dttm, user, text): UserLine.__init__(self, dttm, user, text) class Topic(UserLine): """ Channel topic """ def __init__(self, dttm, user, text): UserLine.__init__(self, dttm, user, text) class Network(object): """ IRC network """ def __init__(self, name="default"): self.name = name self.channels = [] self.users = [] def get_channel(self, channame): for netchannel in channels: if string.lower(channame) == string.lower(netchannel.name) : return netchannel newchannel = Channel(channame) self.channels.append(newchannel) return newchannel def get_user(self, nickname): for netuser in users: if string.lower(nickname) == string.lower(user.name) or string.lower(nickname) in map(lambda alt: string.lower(alt), netuser.alternates): return netuser newuser = User(nickname) self.users.append(newuser) class Channel(object): """ IRC channel """ def __init__(self, name): self.name = name self.users = [] self.topics = [] self.messages = [] self.describes = [] self.kicks = [] class User(object): """ IRC user """ def __init__(self, name): self.name = name ## # Functions # def main(): app_version = "0.0.2" print '\n\nSILAN', app_version, '- Simple IRC Log Analyzer - http://slackforge.com/silan/' print 'Copyright (c) 2007 Shidayu ' try: appinstance = Silan() except: print "An unexpected error has occurred:", sys.exc_info()[0] raise ## # Begin Here! # if __name__=="__main__": main()