
Logger errors
By: a guest on
Sep 23rd, 2012 | syntax:
Python | size: 2.96 KB | hits: 28 | expires: Never
class Logger(threading.Thread):
def __init__(self, line):
threading.Thread.__init__(self)
self.line = line
def run(self):
now = datetime.datetime.now()
monthname = lambda month_num:datetime.date(1900,month_num,1).strftime('%B')
channel = None
## Find different actions
if 'JOIN' in line:
data = line.split(':')
actions = data[1].split(' ')
before = data[1]
nick = actions[0].split('!')
nick = nick[0]
if 'JOIN' in before:
insert_line = "[<a href=\"#%02d:%02d:%02d\" id=\"%02d:%02d:%02d\">%02d:%02d:%02d</a>] <span style=\"color:#7CCD7C;\">%s has joined #rswiki</span>" % (now.hour, now.minute, now.second, now.hour, now.minute, now.second, now.hour, now.minute, now.second, nick)
elif 'PRIVMSG' in line:
data = line.split(':',2)
actions = data[1].split(' ')
nick = actions[0].split('!')
nick = nick[0]
nickcolor = md5(nick).hexdigest()[:6]
channel = actions[2]
message = data[2]
insert_line = "[<a href=\"#%02d:%02d:%02d\" id=\"%02d:%02d:%02d\">%02d:%02d:%02d</a>] <<span style=\"color:#%s;font-weight:bold;\">%s</span>> %s" % (now.hour, now.minute, now.second, now.hour, now.minute, now.second, now.hour, now.minute, now.second, nickcolor, nick, message)
if channel == '#rswiki':
if os.path.exists('../logs/%s-%s-%s.html' % (now.day, now.month, now.year)):
logging_file = open('../logs/%s-%s-%s.html' % (now.day, now.month, now.year), 'a')
logging_file.write('%s<br />' % insert_line)
logging_file.close()
else:
logging_file = open('../logs/%s-%s-%s.html' % (now.day, now.month, now.year), 'w+')
logging_file.write("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>#rswiki logs</title>
<meta name="author" content="Hairr"/>
<style>
body {
background:#e6deee;
}
#title {
font-weight:bold;
margin-bottom:10px;
font-size:200%%;
}
a {
color:#352447;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
</style>
</head>
<body>
<div id="title" align="center">#rswiki | %s-%s-%s</div>
%s<br />""" % (now.day, now.month, now.year, insert_line))
logging_file.close()
index_file = open('../logs/index.html', 'a')
index_file.write('• <a href="%s-%s-%s.html">%s %s, %s</a><br />' % (now.day, now.month, now.year, now.day, monthname(now.month), now.year))
index_file.close()