Last active
December 27, 2015 09:59
-
-
Save SarahLKelley/7308342 to your computer and use it in GitHub Desktop.
A python script for handling hoist log files
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/env python | |
| # hoistlogscript.py | |
| # A python script for handling hoist log files | |
| # | |
| # | |
| # Author: Sarah Kelley <[email protected]> | |
| # 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line handler pattern: