Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # log lines
- # ip,site,status_code
- # Store some data
- log_lines = []
- # Create the menu
- #
- # Menu should be able to load a log file and display some stats
- # if there is nothing laoded show an error and reprompt
- exit = False
- while not exit:
- print("1: Load file")
- print("2: Show num lines")
- print("3: Show errors by status message")
- print("4: Exit")
- opt = input("Enter option from above")
- if opt == 1:
- file_name = input("Enter file name:")
- # can do some check if file is valid or not
- with open(file_name) as f:
- log_lines = f.readlines()
- elif opt == 2:
- print(f"num log lines={len(log_lines)}")
- elif opt == 3:
- status_codes = {}
- for line in log_lines:
- line_data = line.split(",")
- if line_data[2] not in status_codes:
- status_codes[line_data[2]] = 1
- else:
- status_codes[line_data[2]] += 1
- print("Status codes counts")
- for s_code in status_codes:
- print(f"Code={s_code} Count={status_codes[s_code]}")
- elif opt == 4:
- exit = True
- else:
- print("Invalid option, please ree-nter\n")
Add Comment
Please, Sign In to add comment