3
3
from version import __version__ , __commit__
4
4
from Log import Log
5
5
from figshare .Article import Article
6
- from time import asctime
6
+ from datetime import datetime
7
7
from Config import Config
8
8
from figshare .Collection import Collection
9
9
from pathlib import Path
@@ -41,12 +41,14 @@ def check_logs_path_access(config_file):
41
41
42
42
logs_access = os .access (log_location , os .W_OK )
43
43
if (logs_access is False ):
44
- print (asctime () + ":ERROR: Log - " + "The logs location specified in the config file could not be reached or read." )
44
+ print (datetime .now ().strftime ("%Y-%m-%d %H:%M:%S,%f" )[:- 3 ] + ":ERROR: "
45
+ + "The logs location specified in the config file could not be reached or read." )
45
46
exit ()
46
47
47
48
except OSError as error :
48
49
print (error )
49
- print (asctime () + ":ERROR: Log - " + "The logs location specified in the config file could not be reached or read." )
50
+ print (datetime .now ().strftime ("%Y-%m-%d %H:%M:%S,%f" )[:- 3 ] + ":ERROR: "
51
+ + "The logs location specified in the config file could not be reached or read." )
50
52
exit ()
51
53
52
54
@@ -56,15 +58,15 @@ def main():
56
58
Setting up required variables and conditions.
57
59
"""
58
60
global args
59
- print (asctime () + ":Info: Log - ReBACH script has started." )
61
+ print (datetime . now (). strftime ( "%Y-%m-%d %H:%M:%S,%f" )[: - 3 ] + ":INFO: ReBACH script has started." )
60
62
61
63
# Check .env file exists.
62
64
if not args .xfg .is_file ():
63
- print (asctime () + ":ERROR: Log - " + "Configuration file is missing or cannot be read." )
65
+ print (datetime . now (). strftime ( "%Y-%m-%d %H:%M:%S,%f" )[: - 3 ] + ":ERROR: " + "Configuration file is missing or cannot be read." )
64
66
exit ()
65
67
env_file = str (args .xfg )
66
- print (asctime () + ":Info: Log - " + "Env file:" + env_file )
67
- print (asctime () + ":Info: Log - " + "Checking configuration file." )
68
+ print (datetime . now (). strftime ( "%Y-%m-%d %H:%M:%S,%f" )[: - 3 ] + ":INFO: " + "Env file:" + env_file )
69
+ print (datetime . now (). strftime ( "%Y-%m-%d %H:%M:%S,%f" )[: - 3 ] + ":INFO: " + "Checking configuration file." )
68
70
config_obj = Config (env_file )
69
71
70
72
figshare_config = config_obj .figshare_config ()
@@ -80,10 +82,10 @@ def main():
80
82
81
83
# Check required env variables exist.
82
84
if (log_location == "" ):
83
- print (asctime () + ":ERROR: Log - " + "Logs file path missing in .env.ini file." )
85
+ print (datetime . now (). strftime ( "%Y-%m-%d %H:%M:%S,%f" )[: - 3 ] + ":ERROR: " + "Logs file path missing in .env.ini file." )
84
86
exit ()
85
87
86
- log .write_log_in_file ('info' , "Logs location is accessible. Logging will now start." , True )
88
+ log .write_log_in_file ('info' , "Logs location is accessible. Logging to file will now start." , True )
87
89
88
90
if (figshare_api_url == "" or figshare_api_token == "" ):
89
91
log .write_log_in_file ('error' , "Figshare API URL and Token is required." , True , True )
@@ -129,18 +131,17 @@ def main():
129
131
+ " not be reached or read." ,
130
132
True , False )
131
133
132
- return env_file
134
+ return env_file , log
133
135
134
136
135
137
if __name__ == "__main__" :
136
138
get_args ()
137
- config_file_path = main ()
138
- log = Log (config_file_path )
139
+ config_file_path , log = main ()
139
140
140
141
log .write_log_in_file ('info' ,
141
142
"Fetching articles..." ,
142
143
True )
143
- article_obj = Article (config_file_path , args .ids )
144
+ article_obj = Article (config_file_path , log , args .ids )
144
145
article_data = article_obj .get_articles ()
145
146
log .write_log_in_file ('info' ,
146
147
f"Total articles fetched: { len (article_data )} ." ,
@@ -150,7 +151,7 @@ def main():
150
151
log .write_log_in_file ('info' ,
151
152
"Fetching collections..." ,
152
153
True )
153
- collection_obj = Collection (config_file_path , args .ids )
154
+ collection_obj = Collection (config_file_path , log , args .ids )
154
155
collection_data = collection_obj .get_collections ()
155
156
log .write_log_in_file ('info' ,
156
157
f"Total collections fetched: { len (collection_data )} ." ,
0 commit comments