forked from amstan/IRC-Analysis-Toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupybotParser.py
executable file
·57 lines (45 loc) · 1.35 KB
/
supybotParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
#Parses supybot's logfiles. Format Example:
#2010-09-10T01:13:23 <amstan> heheh
#2010-09-10T01:51:20 *** lava <lava!~lava-699.233.432.400.austin.res.rr.com> has quit IRC (Quit: Konversation Terminated)
import string
import sys
ACTION, MISC, MSG = range(3)
#From supybot
_rfc1459trans = string.maketrans(string.ascii_uppercase + r'\[]~',
string.ascii_lowercase + r'|{}^')
def toLower(s, casemapping=None):
"""s => s
Returns the string s lowered according to IRC case rules."""
if casemapping is None or casemapping == 'rfc1459':
return s.translate(_rfc1459trans)
elif casemapping == 'ascii': # freenode
return s.lower()
else:
raise ValueError, 'Invalid casemapping: %r' % casemapping
def parseLog(reader):
log = []
nicks = set()
for line in reader:
date, _, nick, msg = line.split(' ',3)
if nick=="*":
linetype = ACTION
nick, msg = msg.split(' ',1)
elif nick=="***":
linetype = MISC
nick, msg = msg.split(' ',1)
else:
linetype = MSG
nick = nick[1:-1]
nick=toLower(nick.rstrip("_"))
msg=toLower(msg)
nicks.add(nick)
log.append([linetype,date,nick,msg])
#show progress
print "Parsing logs @ %s" % (date)
sys.stdout.flush()
return log, nicks
if __name__ == "__main__":
import LogReader
reader=LogReader.LogReader(sys.argv[1:])
print parseLog(reader)