-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
56 lines (45 loc) · 1.78 KB
/
log.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
52
53
54
55
56
import re
from datetime import datetime
from colorama import init
import params
# fix colorama colors in windows console
init(convert=True)
log_filename = ''
def set_log_file(file_path, file_name):
'''
Establece la carpeta/nombre del archivo donde se guardarán los logs
'''
global log_filename
log_filename = f'{file_path}/{file_name} - Log.txt'
def log(arg, _print=True):
'''
Print en consola que además guarda un archivo log si está activado
'''
if _print:
print(arg)
if params.use_log:
with open(f"{log_filename}", "a", encoding="utf-8") as file:
date = datetime.today().strftime('%Y-%m-%d %Hhs%Mm%Ss')
if arg == '\n':
file.write(arg)
else:
# ansi scape tor emove colorama colors
arg = re.compile(
r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]').sub('', arg)
file.write(f'{date} {arg}\n')
def log_params():
'''
Guarda parámetros de configuración el log sin printear en consola
'''
log('\n', False)
log('Parámetros de búsqueda:', False)
log(f'-> File output: ' + str(params.file_output), False)
log(f'-> File input: {str(params.file_input)}', False)
log(f'-> Join separator: {str(params.join_separator)}', False)
log(f'-> Main search: {str(params.main_search)}', False)
log(f'-> Secondary search: {str(params.secondary_search)}', False)
log(f'-> Country filter: {str(params.country_filter)}', False)
log(f'-> Min score relevance: {str(params.custom_filters)}', False)
log(f'-> Type: {str(params.type)}', False)
log(f'-> Use accent Variations: {str(params.use_accent_variations)}', False)
log(f'-> Works columns to save: {str(params.works_columns_to_save)}', False)