All pastes #52499 Raw Edit

Someone

public text v1 · immutable
#52499 ·published 2006-05-01 03:49 UTC
rendered paste body
import sys
import os
import string
import time


def add_log(raw):
    loctime = '[%s:%s]' % (time.localtime()[3], time.localtime()[4])
    nick = raw.split(":",1)[1].split("!",1)[0]
    try:
        ident = raw.split("!",1)[1].split()[0]
    except:
        pass
    fileextension = '%s%s%s' %(time.localtime()[0], time.localtime()[1], time.localtime()[2])
    partsofraw = string.split(raw)
    filename = 'rilinux.log.%s' % (fileextension)
    try:
        if partsofraw[1] == 'PRIVMSG' and partsofraw[2].startswith('#'):
            line = '%s <%s> %s' % (loctime, nick, raw.split(':',2)[2])
    
        if partsofraw[1] == 'NICK':
            line = '%s Nick change: %s -> %s' % (loctime, nick, raw.split(':',2)[2])
    
        if partsofraw[1] == 'QUIT':
            line = '%s %s (%s) left irc: %s' % (loctime, nick, ident, raw.split(':',2)[2])

        if partsofraw[1] == 'JOIN':
            line = '%s %s (%s) joined %s.' % (loctime, nick, ident, raw.split(':',2)[2])
    
        if partsofraw[1] == 'KICK':
            line = '%s %s kicked from %s by %s :%s' % (loctime, partsofraw[3], partsofraw[2], nick, raw.split(':',2)[2])
    
        if partsofraw[1] == 'MODE':
            line = '%s %s: mode change \'%s %s\' by %s!%s' % (loctime, partsofraw[2], partsofraw[3], partsofraw[4], nick, ident)
    
        if partsofraw[1] == 'PART':
            line = '%s %s (%s) left %s.' % (loctime, nick, ident, partsofraw[2])
       
        if partsofraw[1] == 'TOPIC':
            line = '%s Topic changed on %s by %s!%s:%s' % (loctime, partsofraw[2], nick, ident, raw.split(':',2)[2])
       
        if partsofraw[1] == 'PRIVMSG' and partsofraw[2].startswith('#') and raw.split(':',2)[2].startswith('ACTION'):
            line = '%s Action: %s %s' % (loctime, nick, raw.split('ACTION',1)[1])
    
        if not os.path.isfile(filename):
            first_line = '[00:00] --- %s' % (get_date())
            logfile = open(filename, "w")
            logfile.write(first_line+'\n')
            logfile.write(line)
            logfile.close()
        else:
            logfile = open(filename, "a")
            logfile.write(line)
            logfile.write('\n')
            logfile.close()
       
    except: pass
def get_date():
    weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    months = ['Jan' , 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    weekday = weekdays[time.localtime()[2]]
    day = time.localtime()[2]
    month = months[time.localtime()[1]]
    year = time.localtime()[0]
    date_ful = '%s %s %s %s' % (weekday, months, day, year)
    return date_ful