23 lines
650 B
Python
23 lines
650 B
Python
def percent_ok(log_filename):
|
|
total_reguest = 0
|
|
successfull_reguest = 0
|
|
try:
|
|
with open(log_filename,'r',encoding='utf-8') as f:
|
|
for line in f:
|
|
if not line.strip():
|
|
continue
|
|
|
|
total_reguest+=1
|
|
status = line.strip().split('|')[-1].split(':')[-1].strip()
|
|
|
|
if status == '200':
|
|
successfull_reguest+=1
|
|
|
|
if total_reguest == 0:
|
|
return 0.0
|
|
|
|
result=(successfull_reguest / total_reguest)*100
|
|
return round(result,1)
|
|
except FileNotFoundError:
|
|
return f'Файл не найден'
|