-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinc_etc.py
51 lines (46 loc) · 1.1 KB
/
inc_etc.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
47
48
49
50
51
# -*- coding: utf-8 -*-
__title__ = "ETC for ProxyGrablin"
__description__ = "Various basic functions for project 'ProxyGrablin'."
__author__ = "DrPython3"
__date__ = "2024-10-03"
__version__ = "0.1"
__contact__ = "https://github.com/DrPython3"
# Needed modules:
import sys
import os
from datetime import datetime
# Functions:
def logging(text):
"""
Saves logs to a textfile.
:param str text: log to write
:return: True (saved), False (not saved)
"""
output_file = str("logs.txt")
timestamp = datetime.now()
logtime = str(timestamp.strftime("%Y-%m-%d %H:%M:%S"))
try:
os.makedirs("logs")
except:
pass
try:
logfile = str(os.path.join("logs", str(f"{output_file}")))
with open(logfile, "a+") as target_file:
target_file.write(f"{logtime} | {text}\n")
return True
except:
return False
def writer(output, output_file):
"""
Saves a given output to a text file.
:param output: output to write (list)
:param output_file: file to store the output
:return: None
"""
try:
with open(output_file, "w") as file:
for item in output:
file.write(item + "\n")
except:
pass
# DrPython3 (C) 2024