#!/usr/bin/env python # hoistlogscript.py # A python script for handling hoist log files # # # Author: Sarah Kelley # Created: Monday November 4 """ A script for getting information from hoist log files """ from sys import argv script, filename = argv time_search = "real" p_search = "products" s_search = "SKU" def getTimeJob(logfile): logfile = open(logfile) logfile = logfile.readlines() time_job = 0 for line in logfile: if time_search in line and "ERROR" not in line: line = line.strip() line = line[0:4] line = float(line) time_job = time_job + line return time_job def getProducts(logfile): products = 0 logfile = open(logfile) logfile = logfile.readlines() for line in logfile: if p_search in line: line = line.strip() line = line.split() line = line[2] line = int(line) products = products + line return products def getSku(logfile): sku_records = 0 logfile = open(logfile) logfile = logfile.readlines() for line in logfile: if s_search in line: line = line.strip() line = line.split() line = line[5] line = int(line) sku_records = sku_records + line return sku_records if __name__ == "__main__": time_job = getTimeJob(filename) products = getProducts(filename) sku_records = getSku(filename) print "The time was %s seconds." % time_job print "The number of products is: %s." % products print "The number of SKU records is: %s." % sku_records