-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathOfLogSplitting.py
More file actions
39 lines (33 loc) · 1.32 KB
/
PathOfLogSplitting.py
File metadata and controls
39 lines (33 loc) · 1.32 KB
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
from os.path import exists
from os import mkdir
from time import time
from json import load
with open("config.json", "r") as f:
config = load(f)
log_file_path = config["Original Log File Path"]
output_folder_path = config["Output Folder Path"]
if "Client.txt" not in log_file_path:
log_file_path += "/Client.txt"
start_time = time()
with open(log_file_path, "r", encoding="utf-8") as original_file:
line = original_file.readline()
last_saved_date = line[:10]
raw_text = ""
while len(line)>0:
if "INFO Client" in line:
current_date = line[:10]
raw_text += line
if last_saved_date != current_date:
year = current_date[:4]
new_folder = f"{output_folder_path}/{year}"
if not exists(new_folder):
mkdir(new_folder)
new_path = f"{new_folder}/{current_date.replace('/','_')}.txt"
if not exists(new_path):
print(f"Saving {current_date.replace('/','_')}.txt", end="\r")
with open(new_path, "w", encoding="utf-8") as new_file:
new_file.write(raw_text)
last_saved_date = line[:10]
raw_text = ""
line = original_file.readline()
print(f"Took {(time()-start_time):.2f} seconds to run.")