-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_vimlog.py
More file actions
36 lines (28 loc) · 801 Bytes
/
Copy pathparse_vimlog.py
File metadata and controls
36 lines (28 loc) · 801 Bytes
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
#!/usr/bin/python
"Get stats about yesterdays commands from bash log."
import datetime
import operator
import sys
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
yesterday = yesterday.strftime('%Y%m%d')
def parse_logfile(logfile, daystr):
cmds = {}
for line in open(logfile):
if not line.startswith(daystr):
continue
fields = line.strip().split()
try:
cmd = fields[3]
cmds[cmd] = cmds.get(cmd, 0) + 1
except:
continue
return cmds
def yield_inorder(mydict, min):
inorder = sorted(mydict.iteritems(), key=operator.itemgetter(1),
reverse=True)
for k, c in inorder:
if c > min:
yield k, c
logfile = '/home/mote/logs/vim_history.log'
cmds = parse_logfile(logfile, yesterday)
print 'saved-total', sum(cmds.values())