CPyUG Top 100

23号  <no.0023@gmail.com>
sender-time     Sent at 13:26 (GMT+08:00). Current time there: 8:31 PM. ✆
reply-to        python-cn@googlegroups.com
to      python-cn@googlegroups.com
date    Fri, Mar 19, 2010 at 13:26
subject [CPyUG] [OT] 比较无聊,写一个CPyUG Top 100

代码

Toggle line numbers
   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
jhuangjiahua@gmail.com : 966
limodou@gmail.com : 960
askfor@gmail.com : 908
zoom.quiet@gmail.com : 834
zhicheng1988@gmail.com : 625
linjunhalida@gmail.com : 544
march.liu@gmail.com : 524
smallfish.xy@gmail.com : 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]

MiscItems/2010-03-19 (last edited 2010-03-19 12:33:26 by ZoomQuiet)