Last active
August 29, 2015 14:03
-
-
Save prakhar1989/3557bc082bfdf57656b8 to your computer and use it in GitHub Desktop.
Log Analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2.7 | |
import re | |
from collections import Counter | |
import sys | |
def do_analysis(data): | |
date_map = dict() | |
for l in data: | |
date_patt = re.compile("\[(.*)\]") | |
date_str = date_patt.findall(l)[0][:20] | |
(day, month, hour, minute) = (date_str[:2], date_str[3:6], date_str[12:14], date_str[15:17]) | |
if (day + month) in date_map: | |
date_map[day + month].append(hour + minute) | |
else: | |
date_map[day + month] = [hour + minute] | |
for date in date_map: | |
c = Counter(date_map[date]) | |
for t in c: | |
print "%s, %d" % (t, c[t]) | |
if __name__ == "__main__": | |
data = sys.stdin.readlines() | |
do_analysis(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get file URL by clicking on the Raw link