-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-stats.py
executable file
·54 lines (47 loc) · 1.33 KB
/
0-stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python3
"""
Module 0-stats
Exercice Log parsing
"""
import sys
import traceback
import re
def main():
"""
main
"""
size = 0
counter = 0
status_map = {}
pattern = re.compile("[0-9][0-9][0-9]")
line_parsed2 = []
try:
for line in sys.stdin:
""" jose """
if "-[" in line:
line = line.replace("-[", " - [")
line_parsed = line.split()
if len(line_parsed) >= 8:
if pattern.match(line_parsed[7]):
key = line_parsed[7]
status_map[key] = status_map.get(key, 0) + 1
if len(line_parsed) >= 9:
size += int(line_parsed[8])
counter += 1
if counter % 10 == 0:
print_result(size, status_map)
except KeyboardInterrupt:
""" Keyboard interruption """
traceback.print_exc() # Print the traceback when interrupted
sys.exit(1) # Exit with a non-zero status code
finally:
""" """
# Print the final statistics
print_result(size, status_map)
def print_result(size, status_map):
""" print_result """
print("File size: {}".format(size))
for key, value in sorted(status_map.items()):
print("{}: {}".format(key, value))
if __name__ == "__main__":
main()