import sys from datetime import datetime from pprint import pprint as pp import os def get_file_paths(directory): for dirpath,_,filenames in os.walk(directory): if not filenames: print "No files in dir" for f in filenames: yield os.path.abspath(os.path.join(dirpath, f)) time_format = '%Y-%m-%d %H:%M:%S' ts = [] for f in get_file_paths(sys.argv[1]): log_lines = [line.split('][')[0][1:] for line in open(f) if line.startswith('[')] start, stop = [datetime.strptime(log_lines[0], time_format), datetime.strptime(log_lines[-1], time_format)] ts.append((stop - start).total_seconds()) minsecs = min(ts) maxsecs = max(ts) average = float(sum(ts)) / len(ts) print len(ts), minsecs / 60.0, average / 60.0, maxsecs / 60.0