Contents
CPyUG Top 100
23号 <[email protected]> sender-time Sent at 13:26 (GMT+08:00). Current time there: 8:31 PM. ✆ reply-to [email protected] to [email protected] date Fri, Mar 19, 2010 at 13:26 subject [CPyUG] [OT] 比较无聊,写一个CPyUG Top 100
代码
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3
4 import re, sys, os
5 from operator import itemgetter
6 from collections import defaultdict
7
8 pat = re.compile('From:\s+?.*<([\da-z_\.-]+@[\da-z\.-]+)>')
9 mails = defaultdict(int)
10 for line in open(sys.argv[1], 'rb'):
11 if line[0] != 'F': continue
12 mat = pat.match(line)
13 if mat:
14 mails[mat.group(1)] += 1
15
16 lst = sorted(mails.iteritems(), key=itemgetter(1), reverse=True)
17 for t in lst[:100 if 100 < len(lst) else len(lst)]:
18 print '%s : %d' % (t[0].ljust(16), t[1])
试跑
Shell:~ >: python CPyUG_Top100.py Mail/CPyUG [email protected] : 966 [email protected] : 960 [email protected] : 908 [email protected] : 834 [email protected] : 625 [email protected] : 544 [email protected] : 524 [email protected] : 455 ... python CPyUG_Top100.py Mail/CPyUG 4.10s user 0.22s system 99% cpu 4.332 total Shell:~ >:
反馈
创建 by -- ZoomQuiet [2010-03-19 12:33:26]