55import time
66
77import attr
8+ import structlog
89
910op = operator .attrgetter ('name' )
1011Field = partial (attr .ib , default = None )
1112
13+ logger = structlog .get_logger ()
14+
1215
1316class Client :
1417 def __init__ (self , url , email , password ):
1518 self .url = url
16- print ('Initializing client' )
19+ logger . info ('Initializing client' )
1720 data = {'email' : email , 'password' : password }
1821 header = {'content-type' : 'application/json' , 'accept' :
1922 'application/json' }
@@ -25,7 +28,7 @@ def __init__(self, url, email, password):
2528 self .user_full_name = status ['fullname' ]
2629 self .cookies = cookies
2730 self .header = header
28- print (f'Authenticated to { self .url } as ' f'{ self .user_full_name } ' )
31+ logger . info (f'Authenticated to { self .url } as ' f'{ self .user_full_name } ' )
2932
3033 def get_record (self , uuid , rec_type ):
3134 """Retrieve an individual record of a particular type."""
@@ -39,7 +42,7 @@ def get_record(self, uuid, rec_type):
3942 elif rec_type == 'collections' :
4043 rec_obj = self ._pop_inst (Collection , record )
4144 else :
42- print ('Invalid record type.' )
45+ logger . info ('Invalid record type.' )
4346 exit ()
4447 return rec_obj
4548
@@ -52,7 +55,7 @@ def filtered_item_search(self, key, string, query_type,
5255 endpoint = f'{ self .url } /rest/filtered-items?query_field[]='
5356 endpoint += f'{ key } &query_op[]={ query_type } &query_val[]={ string } '
5457 endpoint += f'{ selected_collections } &limit=200&offset={ offset } '
55- print (endpoint )
58+ logger . info (endpoint )
5659 response = requests .get (endpoint , headers = self .header ,
5760 cookies = self .cookies ).json ()
5861 items = response ['items' ]
@@ -117,4 +120,4 @@ class MetadataEntry(BaseRecord):
117120def elapsed_time (start_time , label ):
118121 """Calculate elapsed time."""
119122 td = datetime .timedelta (seconds = time .time () - start_time )
120- print (f'{ label } : { td } ' )
123+ logger . info (f'{ label } : { td } ' )
0 commit comments