@@ -191,7 +191,7 @@ def export_queued_data_rows(self, timeout_seconds=120):
191
191
self .uid )
192
192
time .sleep (sleep_time )
193
193
194
- def video_label_generator (self , timeout_seconds = 600 ):
194
+ def video_label_generator (self , timeout_seconds = 600 , ** kwargs ):
195
195
"""
196
196
Download video annotations
197
197
@@ -200,7 +200,8 @@ def video_label_generator(self, timeout_seconds=600):
200
200
"""
201
201
_check_converter_import ()
202
202
json_data = self .export_labels (download = True ,
203
- timeout_seconds = timeout_seconds )
203
+ timeout_seconds = timeout_seconds ,
204
+ ** kwargs )
204
205
if json_data is None :
205
206
raise TimeoutError (
206
207
f"Unable to download labels in { timeout_seconds } seconds."
@@ -215,7 +216,7 @@ def video_label_generator(self, timeout_seconds=600):
215
216
"Or use project.label_generator() for text and imagery data." )
216
217
return LBV1Converter .deserialize_video (json_data , self .client )
217
218
218
- def label_generator (self , timeout_seconds = 600 ):
219
+ def label_generator (self , timeout_seconds = 600 , ** kwargs ):
219
220
"""
220
221
Download text and image annotations
221
222
@@ -224,7 +225,8 @@ def label_generator(self, timeout_seconds=600):
224
225
"""
225
226
_check_converter_import ()
226
227
json_data = self .export_labels (download = True ,
227
- timeout_seconds = timeout_seconds )
228
+ timeout_seconds = timeout_seconds ,
229
+ ** kwargs )
228
230
if json_data is None :
229
231
raise TimeoutError (
230
232
f"Unable to download labels in { timeout_seconds } seconds."
@@ -239,7 +241,7 @@ def label_generator(self, timeout_seconds=600):
239
241
"Or use project.video_label_generator() for video data." )
240
242
return LBV1Converter .deserialize (json_data )
241
243
242
- def export_labels (self , download = False , timeout_seconds = 600 ):
244
+ def export_labels (self , download = False , timeout_seconds = 600 , ** kwargs ):
243
245
""" Calls the server-side Label exporting that generates a JSON
244
246
payload, and returns the URL to that payload.
245
247
@@ -251,11 +253,52 @@ def export_labels(self, download=False, timeout_seconds=600):
251
253
URL of the data file with this Project's labels. If the server didn't
252
254
generate during the `timeout_seconds` period, None is returned.
253
255
"""
256
+
257
+ def _string_from_dict (dictionary : dict , value_with_quotes = False ) -> str :
258
+ """Returns a concatenated string of the dictionary's keys and values
259
+
260
+ The string will be formatted as {key}: 'value' for each key. Value will be inclusive of
261
+ quotations while key will not. This can be toggled with `value_with_quotes`"""
262
+ if value_with_quotes :
263
+ return "," .join ([
264
+ f"""{ c } : "{ dictionary .get (c )} \" """ for c in dictionary
265
+ if dictionary .get (c )
266
+ ])
267
+ return "," .join ([
268
+ f"""{ c } : { dictionary .get (c )} """ for c in dictionary
269
+ if dictionary .get (c )
270
+ ])
271
+
272
+ def _validate_datetime (string_date : str ) -> None :
273
+ """helper function validate that datetime is as follows: YYYY-MM-DD for the export"""
274
+ if string_date :
275
+ try :
276
+ datetime .fromisoformat (string_date )
277
+ except :
278
+ raise ValueError ("Format of date must be \" YYYY-MM-DD\" " )
279
+
254
280
sleep_time = 2
255
281
id_param = "projectId"
282
+ filter_param = ""
283
+ filter_param_dict = {}
284
+
285
+ if "start" in kwarg or "end" in kwarg :
286
+ created_at_dict = {
287
+ "start" : kwarg .get ("start" , "" ),
288
+ "end" : kwarg .get ("end" , "" )
289
+ }
290
+ [_validate_datetime (date ) for date in created_at_dict .values ()]
291
+ filter_param_dict ["labelCreatedAt" ] = "{%s}" % _string_from_dict (
292
+ created_at_dict , value_with_quotes = True )
293
+
294
+ if filter_param_dict :
295
+
296
+ filter_param = """, filters: {%s }""" % (_string_from_dict (
297
+ filter_param_dict , value_with_quotes = False ))
298
+
256
299
query_str = """mutation GetLabelExportUrlPyApi($%s: ID!)
257
- {exportLabels(data:{projectId: $%s }) {downloadUrl createdAt shouldPoll} }
258
- """ % (id_param , id_param )
300
+ {exportLabels(data:{projectId: $%s%s }) {downloadUrl createdAt shouldPoll} }
301
+ """ % (id_param , id_param , filter_param )
259
302
260
303
while True :
261
304
res = self .client .execute (query_str , {id_param : self .uid })
0 commit comments