1- import sys
2- sys .path .append ('../' )
31import os
4- #from functools import wraps
52import functools
63import csv
74from datetime import datetime
85
9-
106# root path to the project
11- #ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
12- ROOT_PATH = ''
13- LOG_FILE = 'log.csv'
14- ERROR_FILE = 'error.csv'
7+ # ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
8+ ROOT_PATH = ''
9+ LOG_FILE = 'log.csv'
10+ ERROR_FILE = 'error.csv'
1511LOG_PATH = os .path .join (ROOT_PATH , LOG_FILE )
1612ERROR_PATH = os .path .join (ROOT_PATH , ERROR_FILE )
1713
14+
1815def dialoget (template , logs_path = '' ):
19- USER_ERROR = os .path .abspath ( os .path .join (logs_path ,ERROR_PATH ) )
20- USER_LOGS = os .path .abspath ( os .path .join (logs_path ,LOG_PATH ) )
16+ USER_ERROR = os .path .abspath (os .path .join (logs_path , ERROR_PATH ))
17+ USER_LOGS = os .path .abspath (os .path .join (logs_path , LOG_PATH ))
18+
2119 def decorator (func ):
2220 @functools .wraps (func )
2321 def wrapper (* args , ** kwargs ):
@@ -50,8 +48,10 @@ def wrapper(*args, **kwargs):
5048 return func (* args , ** kwargs )
5149
5250 return wrapper
51+
5352 return decorator
5453
54+
5555def log_to_csv (file_name , log_dict ):
5656 # Write log message or error to a CSV file
5757 with open (file_name , mode = 'a' , newline = '' ) as file :
@@ -60,62 +60,3 @@ def log_to_csv(file_name, log_dict):
6060 writer .writeheader ()
6161 writer .writerow (log_dict )
6262
63-
64- """
65- def dialoget(template):
66- def decorator(func):
67- @functools.wraps(func)
68- def wrapper(*args, **kwargs):
69- # Assuming the function returns a dictionary of replacements
70- replacements = func(*args, **kwargs)
71-
72- # Replace placeholders in the template with actual values
73- filled_template = template.format(**replacements)
74-
75- # Print or use the filled template string
76- print(filled_template) # or you can return it, if needed
77-
78- # Return the result of the function, if it's necessary.
79- return replacements
80-
81- return wrapper
82-
83- return decorator
84-
85-
86-
87- # This is the decorator factory that accepts arguments
88- def dialoget2(sentence="Sentence"):
89- # This is the actual decorator
90- def decorator(func):
91- call_count = 0
92-
93- @functools.wraps(func)
94- def wrapper(*args, **kwargs):
95- nonlocal call_count
96- call_count += 1
97- print(f"The sentence: {sentence} {func.__name__} has been called {call_count} times")
98- return func(*args, **kwargs)
99-
100- return wrapper
101- return decorator
102-
103-
104-
105-
106- # Usage example with decorator arguments
107-
108- def nfunc(func):
109- # This will hold the number of times the function has been called
110- call_count = 0
111-
112- @wraps(func) # Use this to preserve the original function's metadata
113- def wrapper(*args, **kwargs):
114- nonlocal call_count
115- call_count += 1
116- print(f"Function {func.__name__} has been called {call_count} times")
117- return func(*args, **kwargs)
118-
119- return wrapper
120-
121- """
0 commit comments