@@ -23,7 +23,7 @@ def log(log_type: str, text: str):
2323
2424def show_summary ():
2525 current_date = datetime .now ()
26- size_saved = 0.0
26+ size_saved_mb = 0.0
2727 with open (paths .LOG_PATH , "r" , encoding = ENCODING ) as log_file :
2828 for line in log_file :
2929 if "Program startup" in line :
@@ -35,43 +35,28 @@ def show_summary():
3535 timestamp_datetime = datetime .strptime (timestamp , DATE_FORMAT )
3636
3737 if (current_date - timestamp_datetime ).days <= 30 :
38- size_saved += float (size [:- 3 ])
38+ size_saved_mb += float (size [:- 3 ]) # Remove the unit (MB) before adding
3939
40- size_saved /= 1024.0
40+ size_saved_gb = size_saved_mb / 1024.0
4141 notification .show_notification (
4242 "There's nothing to delete!" ,
43- f"You have saved { size_saved :.2f} GB in the last 30 days." ,
43+ f"You have saved { size_saved_gb :.2f} GB in the last 30 days." ,
4444 )
4545
4646
47- def _extract_line_data (line ) -> Tuple [str , str , str , str ]:
48- # sourcery skip: extract-method, inline-variable, remove-unnecessary-else
49- # Define regular expressions to match different parts of the log line
50- timestamp_regex = r"(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}:\d{2})"
51- filename_regex = r"FILE: (.*?) SIZE:"
52- size_regex = r"SIZE: ([\d.]+) (.)B"
53- reason_regex = r"REASON: (.+)"
54-
55- # Compile the regex patterns
56- timestamp_match = re .search (timestamp_regex , line )
57- filename_match = re .search (filename_regex , line )
58- size_match = re .search (size_regex , line )
59- reason_match = re .search (reason_regex , line )
60-
61- # Check if all parts were matched
62- if timestamp_match and filename_match and size_match and reason_match :
63- timestamp = timestamp_match [1 ]
64- filename = filename_match [1 ]
65- # Convert size to float (assuming MB for demonstration)
66- size_value = float (size_match [1 ])
67- if size_match [2 ] == "G" :
68- size_value *= 1024 # Convert to MB if size is in GB
69- size = f"{ size_value :.2f} MB"
70- reason = reason_match [1 ]
71- return timestamp , filename , size , reason
72- else :
73- # print(f"LINE FORMAT INVALID! {filename_match}")
47+ def _extract_line_data (line : str ) -> Tuple [str , str , str , str ]:
48+ filename_regex = r"(FILE|DIR): (.*?) SIZE: ([\d.]+) (GB|MB) REASON: (.+)"
49+ if not (match := re .search (filename_regex , line )):
7450 return "" , "" , "" , ""
51+ timestamp = re .search (r"(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}:\d{2})" , line )[1 ]
52+ filetype = match [1 ]
53+ size_value = float (match [3 ])
54+ size_unit = match [4 ]
55+ if size_unit == "GB" :
56+ size_value *= 1024 # Convert GB to MB
57+ size = f"{ size_value :.2f} MB"
58+ reason = match [5 ]
59+ return timestamp , filetype , size , reason
7560
7661
7762if STARTUP :
0 commit comments