Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time, os, re
- import threading
- log_period = 60 # in seconds
- url_logfolder='https://dl.dropbox.com/u/14131518/log/logs/'
- path_logfolder='C:\\Users\\MolSno\\Dropbox\\Public\\log\\logs\\'
- path_datafolder='C:\\Users\\MolSno\\Dropbox\\Public\\log\\data\\'
- path_logpage=path_datafolder+'logpage.html'
- path_links=path_datafolder+'links.html'
- messages = []
- annoy = True
- class LogMessage(object):
- def __init__(self, nick, message, time, kind, args=[]):
- self.nick = nick
- self.message = message
- self.time = time
- self.kind = kind
- self.args = args
- def dictreplace(text, dic):
- for i, j in dic.items():
- text = text.replace(i, j)
- return text
- def logwrite(phenny, startTimer):
- now = time.localtime(time.time())
- date = time.strftime("%Y-%m-%d", now)
- links_html = open(path_links,'r').read()
- outpath = path_logfolder+date+'.html'
- if os.path.exists(outpath):
- outpage = open(outpath,'r+')
- basepage_html = outpage.read()
- outpage.seek(0)
- outhtml = basepage_html
- else:
- outpage = open(outpath,'w+')
- basepage_html = open(path_logpage).read()
- linkreplace = {\
- '<!--PREVIOUS-->': '#',\
- '<!--NEXT-->': '#'}
- links = dictreplace(links_html, linkreplace)
- outhtml = basepage_html.replace('<!--LINKS-->',links)
- outhtml = outhtml.replace('<!--DATE-->',date)
- # messages don't end up in time order for some reason, fix that
- sortedmessages = sorted(messages, cmp=lambda x,y: cmp(x.time, y.time))
- for m in sortedmessages:
- msg_html = open(path_datafolder+'messages\\'+m.kind+'.html','r').read().encode('utf8')
- print path_datafolder+'messages\\'+m.kind+'.html'
- # do the html cleaning thing
- parsedmsg = dictreplace(m.message, {'<':'<', '>':'>', '&':'&'})
- # general formatting
- bold = False
- uline = False
- link = False
- ital = False
- fgcolor = '65535' # "default" value... yeah
- bgcolor = '65535'
- outs = '<span class="fg_65535"><span class="bg_65535">'
- i = 0
- while i < len(parsedmsg):
- if parsedmsg[i] == '\x02':
- bold = not bold
- if bold: outs+= '<b>'
- if not bold: outs+= '</b>'
- elif parsedmsg[i] == '\x1f':
- uline = not uline
- if uline: outs+= '<u>'
- if not uline: outs+= '</u>'
- elif parsedmsg[i] == '\x16':
- ital = not ital
- if ital: outs+= '<i>'
- if not ital: outs+= '</i>'
- elif parsedmsg[i] == '\x03':
- j = i+1;
- tmpfg = ''
- tmpbg = ''
- did = False
- if re.match('[0-9]',parsedmsg[j]):
- while re.match('[0-9]',parsedmsg[j]):
- tmpfg+= parsedmsg[j]
- j+=1
- fgcolor=str(int(tmpfg))
- did = True
- if parsedmsg[j] == ',':
- if re.match('[0-9]',parsedmsg[j+1]):
- j+=1
- while re.match('[0-9]',parsedmsg[j]):
- tmpbg+= parsedmsg[j]
- j+=1
- bgcolor=str(int(tmpbg))
- did = True
- if did == False:
- fgcolor = '65535'
- bgcolor = '65535'
- outs+='</span></span><span class="fg_'+fgcolor+'"><span class="bg_'+bgcolor+'">'
- i = j - 1;
- elif parsedmsg[i] == '\x0f':
- outs+='</span></span><span class="fg_65535"><span class="bg_65535">'
- if bold:
- outs+='</b>'
- if uline:
- outs+='</u>'
- if ital:
- outs+='</i>'
- elif ord(parsedmsg[i]) > 127:
- outs+='&#'+str(ord(parsedmsg[i]))
- else:
- outs+= parsedmsg[i]
- i+=1
- if bold:
- outs+='</b>'
- if uline:
- outs+='</u>'
- outs+='</span></span>'
- parsedmsg = outs
- args = m.args if len(m.args) > 0 else 'err: invalid field'
- msgreplace = {\
- '<!--NICK-->': m.nick,\
- '<!--MESSAGE-->': parsedmsg,\
- '<!--TIME-->': time.strftime("%a %b %d, %I:%M:%S %p", m.time),\
- '<!--TARGET-->': args[1]}
- outhtml = outhtml.replace('<!--NEXT_MESSAGE-->', dictreplace(msg_html, msgreplace)+'\r\n<!--NEXT_MESSAGE-->')
- messages.remove(m)
- outpage.write(outhtml.encode('utf8'))
- print 'logging: logs written'
- t = threading.Timer(log_period, logwrite, [phenny, True])
- t.start()
- def logs(phenny, input):
- now = time.localtime(time.time())
- date = time.strftime("%Y-%m-%d", now)
- phenny.say(url_logfolder+date+'.html')
- logwrite(phenny, False)
- logs.commands = ['logs']
- logs.priority = 'high'
- logs.thread = False
- def memlogPRIVMSG(phenny, input):
- if input.sender == '#radar':
- if input.group(0).startswith('\x01ACTION') and input.group(0).endswith('\x01'):
- messages.append(LogMessage(input.nick, input.group(0)[len('\x01ACTION'):], time.localtime(time.time()), 'PRIVMSG_ACTION'))
- else:
- messages.append(LogMessage(input.nick, input.group(0), time.localtime(time.time()), 'PRIVMSG'))
- memlogPRIVMSG.event = 'PRIVMSG'
- memlogPRIVMSG.rule = r'.*'
- def memlogQUIT(phenny, input):
- messages.append(LogMessage(input.nick, input.group(0), time.localtime(time.time()), 'QUIT'))
- memlogQUIT.event = 'QUIT'
- memlogQUIT.rule = r'.*'
- def memlogJOIN(phenny, input):
- messages.append(LogMessage(input.nick, input.group(0), time.localtime(time.time()), 'JOIN'))
- memlogJOIN.event = 'JOIN'
- memlogJOIN.rule = r'.*'
- def memlogPART(phenny, input):
- messages.append(LogMessage(input.nick, input.group(0), time.localtime(time.time()), 'PART'))
- memlogPART.event = 'PART'
- memlogPART.rule = r'.*'
- def memlogKICK(phenny, input):
- messages.append(LogMessage(input.nick, input.group(0), time.localtime(time.time()), 'KICK', input.args))
- memlogKICK.event = 'KICK'
- memlogKICK.rule = r'.*'
- def memlogMODE(phenny, input):
- messages.append(LogMessage(input.nick, input.group(0), time.localtime(time.time()), 'MODE'))
- memlogMODE.event = 'MODE'
- memlogMODE.rule = r'.*'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement