-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc_crements.py
executable file
·50 lines (42 loc) · 1.5 KB
/
irc_crements.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
#!/usr/bin/env python
# Richard Darst, June 2011
import collections
import datetime
import re
import sys
from irclogparser import LogParser
r = re.compile(r'([a-z1-9][a-z1-9-]{2,}) ?(\+\+|--)', re.I)
def count(iterable, value):
return len([x for x in iterable if x==value])
allnicks = set()
crements = collections.defaultdict(list)
crementers = collections.defaultdict(list)
fname = sys.argv[1]
for message, nick, line, LP in LogParser(open(fname)):
# skip early dates
if LP.time < datetime.datetime(2011,1,1): continue
# skip non-messages
if message != "msg": continue
sayerNick = nick.lower()
allnicks |= set((sayerNick, ))
m = r.search(line)
if not m: continue
nick, crementString = m.groups()
nick = nick.lower()
print sayerNick, nick, crementString
if nick == sayerNick: continue
if crementString == "++":
crement = +1
elif crementString == "--":
crement = -1
else:
raise Exception("unknown crement")
crements[nick].append(crement)
crementers[sayerNick].append(nick)
for nick, crements in sorted(crements.iteritems(), key=lambda (k,v): sum(v), reverse=True):
#if nick not in allnicks: continue
print "%3d -%3d =%3d %s"%(count(crements, 1), count(crements, -1), sum(crements), nick)
#for nick in crementers:
# crementers[nick] = [x for x in crementers[nick] if x in allnicks]
for nick, crements in sorted(crementers.iteritems(), key=lambda (k,v): len(v), reverse=True):
print "%3d %s"%(len(crements), nick)