Skip to content

Instantly share code, notes, and snippets.

@SarahLKelley
Last active December 27, 2015 09:59
Show Gist options
  • Save SarahLKelley/7308342 to your computer and use it in GitHub Desktop.
Save SarahLKelley/7308342 to your computer and use it in GitHub Desktop.
A python script for handling hoist log files
#!/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
@bbengfort
Copy link

Line handler pattern:

from sys import argv

def abc_finder(line):
    return line.count('A') + line.count('B') + line.count('C')

def def_finder(line):
    return line.count('D') + line.count('E') + line.count('F')

def gih_finder(line):
    return line.count('G') + line.count('I') + line.count('H')

def xyz_finder(line):
    passs

def main(argv):
    script, filename = argv

    ABC = 0
    DEF = 0
    GIH = 0

    with open(filename, 'r') as logfile:
        for line in logfile:
            line = line.strip()
            ABC += abc_finder(line)
            DEF += def_finder(line)
            GIH += gih_finder(line)

    print "%i ABC" % ABC
    print "%i DEF" % DEF
    print "%i GIH" % GIH

if __name__ == '__main__':
    main(argv)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment