Don't like ads? PRO users don't see any ads ;-)
Guest

Logger errors

By: a guest on Sep 23rd, 2012  |  syntax: Python  |  size: 2.96 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Logger(threading.Thread):
  2.     def __init__(self, line):
  3.         threading.Thread.__init__(self)
  4.         self.line = line
  5.     def run(self):
  6.         now = datetime.datetime.now()
  7.         monthname = lambda month_num:datetime.date(1900,month_num,1).strftime('%B')
  8.         channel = None
  9.         ## Find different actions
  10.         if 'JOIN' in line:
  11.             data = line.split(':')
  12.             actions = data[1].split(' ')
  13.             before = data[1]
  14.             nick = actions[0].split('!')
  15.             nick = nick[0]
  16.             if 'JOIN' in before:
  17.                 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)
  18.         elif 'PRIVMSG' in line:
  19.             data = line.split(':',2)
  20.             actions = data[1].split(' ')
  21.             nick = actions[0].split('!')
  22.             nick = nick[0]
  23.             nickcolor = md5(nick).hexdigest()[:6]
  24.             channel = actions[2]
  25.             message = data[2]
  26.             insert_line = "[<a href=\"#%02d:%02d:%02d\" id=\"%02d:%02d:%02d\">%02d:%02d:%02d</a>] &lt;<span style=\"color:#%s;font-weight:bold;\">%s</span>&gt; %s" % (now.hour, now.minute, now.second, now.hour, now.minute, now.second, now.hour, now.minute, now.second, nickcolor, nick, message)
  27.  
  28.         if channel == '#rswiki':
  29.             if os.path.exists('../logs/%s-%s-%s.html' % (now.day, now.month, now.year)):
  30.                 logging_file = open('../logs/%s-%s-%s.html' % (now.day, now.month, now.year), 'a')
  31.                 logging_file.write('%s<br />' % insert_line)
  32.                 logging_file.close()
  33.             else:
  34.                 logging_file = open('../logs/%s-%s-%s.html' % (now.day, now.month, now.year), 'w+')
  35.                 logging_file.write("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  36. <html>
  37.        <head>
  38.            <title>#rswiki logs</title>
  39.            <meta name="author" content="Hairr"/>
  40.            <style>
  41.            body {
  42.            background:#e6deee;
  43.            }
  44.    
  45.            #title {
  46.            font-weight:bold;
  47.            margin-bottom:10px;
  48.            font-size:200%%;
  49.            }
  50.  
  51.            a {
  52.            color:#352447;
  53.            text-decoration:none;
  54.            }
  55.  
  56.            a:hover {
  57.            text-decoration:underline;
  58.            }
  59.            </style>
  60.        </head>
  61.        <body>
  62.            <div id="title" align="center">#rswiki | %s-%s-%s</div>
  63. %s<br />""" % (now.day, now.month, now.year, insert_line))
  64.                 logging_file.close()
  65.                 index_file = open('../logs/index.html', 'a')
  66.                 index_file.write('&bull; <a href="%s-%s-%s.html">%s %s, %s</a><br />' % (now.day, now.month, now.year, now.day, monthname(now.month), now.year))
  67.                 index_file.close()