#!/usr/bin/python3

# parse keystone.common.wsgi and return number of failed login attempts
loginfail = 0 # counter for fails
successlogin = 0
with open("/home/student/mycode/attemptlogin/keystone.common.wsgi","r") as keystone_file:
    # turn the file into a list of lines in memory

    # loop over the file
    for line in keystone_file:

        # if this 'fail pattern' appears in the line...
        if "- - - - -] Authorization failed" in line:
            loginfail += 1 # this is the same as loginfail = loginfail + 1
            lineSplit = line.split(" ")[-1]
            print(lineSplit)
        else:
            successlogin += 1

    print("The number of failed log in attempts is", loginfail)
    print("The number of success log in attemps is", successlogin)

