All pastes #52503 Raw Edit

Untitled

public python v1 · immutable
#52503 ·published 2006-05-01 04:13 UTC
rendered paste body
import sysimport osimport stringimport timedef add_log(raw):    if time.localtime()[3] < 10:       hour = '0%s' % time.localtime()[3]    else:        hour = time.localtime()[3]            if time.localtime()[4] < 10:       minute = '0%s' % time.localtime()[3]    else:         minute = time.localtime()[3]    loctime = '[%s:%s]' % (hour, minute)    fileextension = '%s%s%s' %(time.localtime()[0], time.localtime()[1], time.localtime()[2])    partsofraw = string.split(raw)    filename = 'rilinux.log.%s' % (fileextension)    events = ['PRIVMSG', 'NICK', 'QUIT', 'JOIN', 'KICK', 'MODE', 'PART', 'TOPIC']        try:       nick = raw.split(":",1)[1].split("!",1)[0]       idented = raw.split("!",1)[1].split()[0]       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, idented, raw.split(':',2)[2])       if partsofraw[1] == 'JOIN':          line = '%s %s (%s) joined %s.' % (loctime, nick, idented, 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, idented)       if partsofraw[1] == 'PART':          line = '%s %s (%s) left %s.' % (loctime, nick, idented, partsofraw[2])       if partsofraw[1] == 'TOPIC':          line = '%s Topic changed on %s by %s!%s :%s' % (loctime, partsofraw[2], nick, idented, raw.split(':',2)[2])       if partsofraw[1] == 'PRIVMSG' and partsofraw[2].startswith('#') and raw.split(':',2)[2].startswith('^AACTION'):          line = '%s Action: %s %s' % (loctime, nick, raw.split('^AACTION',1)[1])       if not os.path.isfile(filename) and line is not None:          first_line = '[00:00] --- %s' % (get_date())          logfile = open(filename, "w")          logfile.write(first_line)          logfile.write('\n')          logfile.write(line)          logfile.close()       elif line is not None:            logfile = open(filename, "a")            logfile.write(line)            logfile.close()    except : passdef 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, month, day, year)    return date_ful