Meta:Tools/Chat/CleanChat.py
< Meta:Tools | Chat
What does it do
This script formats my Xchat logs into a readable form we can paste into http://pasteall.org to report chatlogs in talk pages under SundayMeetingAgenda
It transfoms this:
Feb 22 16:01:02 * kaito has changed the topic to: meeting time! Feb 22 16:01:27 <kaito> we get andy visiting, then it has to be totally clean! Feb 22 16:01:48 <DingTo> :-D Feb 22 16:01:56 <kaito> you know, german's preoccupation with order :) Feb 22 16:03:05 <kaito> so! usual topics? 1) current projects 2) 2.5 + wintercamp 3) 2.49 yes/no? Feb 22 16:03:16 <mal_CanDo> 3) 2.49 or 2.48b? Feb 22 16:03:28 <kaito> or whatever we call it :)
into this:
* kaito has changed the topic to: meeting time! <kaito> we get andy visiting, then it has to be totally clean! <DingTo> :-D <kaito> you know, german's preoccupation with order :) <kaito> so! usual topics? 1) current projects 2) 2.5 + wintercamp 3) 2.49 yes/no? <mal_CanDo> 3) 2.49 or 2.48b? <kaito> or whatever we call it :)
To use it, set DATE to the length of the date of your logs (depends probably from your IRC client, in XChat as you can see above I have a date 16 characters long).
How to execute it
To run it:
- give the file executable permissions:
$ chmod u+x cleanchat.py
- call it with the name of the chatlog as first argument, for example:
$ cleanchat.py 2009-02-22nd.log
In this case it will output a file called "2009-02-22nd_clean.log" under the same folder of "2009-02-22nd.log"
The script
#!/usr/bin/env python
from __future__ import division
import math,sys
chatlog=sys.argv[1]
f=open(chatlog,'r')
f2=open(chatlog.split('.')[0]+'_clean.log','w')
chat=f.readlines()
"""
With Xchat I use DATE=16
Example:
Feb 22 17:12:24 <theeth> xxxxxx
"""
DATE=16
PASTEALL_WIDTH=100
maxlength=0
for line in chat:
print line.split()
if line[DATE:][0]=='<':
name_l=line[DATE:].index('>')
if name_l>maxlength: maxlength=name_l
for line in chat:
line=line[DATE:-1]
L=line[:PASTEALL_WIDTH]
if L[0]=='<':
name_l=L.index('>')
ls=L.split('>')
newline=' '*(maxlength-name_l)+ls[0]+'>'+'>'.join(ls[1:])
if L[0]=='*':
ls=L.split()
newline=' '*maxlength+'*\t'+' '.join(ls[1:])
newline+='\n'
f2.write(newline)
if len(line)>PASTEALL_WIDTH:
repeat=int(math.ceil(len(line)/(PASTEALL_WIDTH-maxlength)))
for i in range(1,repeat):
f2.write(' '*maxlength+'\t'+line[i*PASTEALL_WIDTH:(i+1)*PASTEALL_WIDTH]+'\n')
f2.close()
f.close()