-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_log_to_interview.py
More file actions
66 lines (52 loc) · 2.5 KB
/
convert_log_to_interview.py
File metadata and controls
66 lines (52 loc) · 2.5 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Standard library imports
import datetime
import os
import shutil
import logging
# Third-party library imports
import tkinter as tk
from tkinter import ttk
# Local imports
import importlib
import inspect
from definitions import *
def convert_log_to_interview():
new_log_file = "interview.txt"
format_str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
try:
# Disable logging while the conversion runs
logging.disable(logging.CRITICAL)
# Copy the log file to the interview file
shutil.copyfile(log_file, new_log_file)
# Remove the format string for the logger from each line
with open(new_log_file, "r") as f:
log = f.readlines()
# Get work type and author name from log file
work_type = log[0].split(": ")[1].strip()
author_name = log[1].split(": ")[1].strip()
# Get subject name and interview dates if work type is Biography
if work_type == "Biography":
subject_name = log[2].split(": ")[1].strip()
start_date = datetime.datetime.strptime(log[-1].split(", ")[0], "%Y-%m-%d %H:%M:%S")
end_date = datetime.datetime.strptime(log[3].split(", ")[0], "%Y-%m-%d %H:%M:%S")
interview_duration = str(end_date - start_date)
interview_dates = f"{start_date.strftime('%Y-%m-%d')} to {end_date.strftime('%Y-%m-%d')}"
# Get current date
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
# Get interview details string
interview_details = f"Interview details:\nWork type: {work_type}\nAuthor name: {author_name}\n"
if work_type == "Biography":
interview_details += f"Subject name: {subject_name}\nInterview duration: {interview_duration}\nInterview dates: {interview_dates}\n"
interview_details += f"Current date: {current_date}\n\n"
# Generate interview file
with open(new_log_file, "w") as f:
f.write(interview_details)
for line in log:
if "Generated by FoolsGoldPyWrite" not in line:
f.write(line.replace(format_str, ""))
print("Interview file generated successfully.")
except Exception as e:
print(f"Error while generating interview file, please make sure there is a log file created by this program in the directory {str(e)}")
finally:
# Re-enable logging after the conversion is done
logging.disable(logging.NOTSET)