-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_writer.py
46 lines (38 loc) · 1.7 KB
/
log_writer.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
import os
from datetime import datetime
from custom_types.job import Job
from custom_exceptions import CustomExceptionData
from utils import Singleton
class LogWriter(metaclass=Singleton):
def __init__(self):
"""
Class for writing job application result log in logs folder
"""
current_time_postfix = datetime.now().strftime("-%Y_%m_%d-%H_%M_%S")
self.success_path = os.path.join(".",
"logs",
f"successful{current_time_postfix}.txt")
self.failed_path = os.path.join(".",
"logs",
f"failed{current_time_postfix}.txt")
open(self.success_path, "w", encoding="UTF-8").close()
open(self.failed_path, "w", encoding="UTF-8").close()
def log_success(self, job_data: Job) -> None:
"""
Write successful job application to log
:param job_data: Job object
"""
with open(self.success_path, "a", encoding="UTF-8") as f:
f.writelines("{} ({})\n"
"{}\n"
"Link: {}\n"
"--------------------\n".format(job_data.title, job_data.company,
job_data.location,
job_data.link))
def log_error(self, ex_data: CustomExceptionData) -> None:
"""
Write failed job application to log
:param ex_data: Custom exception object
"""
with open(self.failed_path, "a", encoding="UTF-8") as f:
f.writelines(f"{ex_data}\n" + 120 * "-" + "\n")