Skip to content

Commit 623ce40

Browse files
committed
Add try-except for duration parsing to handle ValueError and TypeError gracefully
1 parent ed3bfdd commit 623ce40

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

infra/scripts/index_scripts/03_cu_process_data_text.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ def get_field_value(fields, field_name, default=""):
330330
conversation_id = file_name.split('convo_', 1)[1].split('_')[0]
331331
conversationIds.append(conversation_id)
332332
fields = result['result']['contents'][0]['fields']
333-
duration = int(get_field_value(fields, 'Duration', '0'))
333+
duration_str = get_field_value(fields, 'Duration', '0')
334+
try:
335+
duration = int(duration_str)
336+
except (ValueError, TypeError):
337+
duration = 0
334338
end_timestamp = str(start_timestamp + timedelta(seconds=duration)).split(".")[0]
335339
start_timestamp = str(start_timestamp).split(".")[0]
336340
summary = get_field_value(fields, 'summary')

infra/scripts/index_scripts/04_cu_process_custom_data.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,14 @@ def get_field_value(fields, field_name, default=""):
371371
start_timestamp = datetime.strptime(start_time, timestamp_format)
372372
conversation_id = file_name.split('convo_', 1)[1].split('_')[0]
373373
conversationIds.append(conversation_id)
374+
374375
fields = result['result']['contents'][0]['fields']
375-
duration = int(get_field_value(fields, 'Duration', '0'))
376+
duration_str = get_field_value(fields, 'Duration', '0')
377+
try:
378+
duration = int(duration_str)
379+
except (ValueError, TypeError):
380+
duration = 0
381+
376382
end_timestamp = str(start_timestamp + timedelta(seconds=duration)).split(".")[0]
377383
start_timestamp = str(start_timestamp).split(".")[0]
378384
summary = get_field_value(fields, 'summary')
@@ -422,11 +428,15 @@ def get_field_value(fields, field_name, default=""):
422428
timestamp_format = "%Y-%m-%d %H_%M_%S" # Adjust format if necessary
423429
start_timestamp = datetime.strptime(start_time, timestamp_format)
424430

425-
conversation_id = file_name.split('convo_', 1)[1].split('_')[0]
426431
conversationIds.append(conversation_id)
427432

428433
fields = result['result']['contents'][0]['fields']
429-
duration = int(get_field_value(fields, 'Duration', '0'))
434+
duration_str = get_field_value(fields, 'Duration', '0')
435+
try:
436+
duration = int(duration_str)
437+
except (ValueError, TypeError):
438+
duration = 0
439+
430440
end_timestamp = str(start_timestamp + timedelta(seconds=duration))
431441
end_timestamp = end_timestamp.split(".")[0]
432442
start_timestamp = str(start_timestamp).split(".")[0]

0 commit comments

Comments
 (0)