'Build a sort specifier in Smartsheet API with Python

I have this function from the Smartsheet SDK:

def evaluate_row_and_build_updates(source_row):
    # Find the cell and value we want to evaluate
    status_cell = get_cell_by_column_name(source_row, "Status")
    status_value = status_cell.display_value
    if status_value == "Complete":
        remaining_cell = get_cell_by_column_name(source_row, "Remaining")
        if remaining_cell.display_value != "0":  # Skip if already 0
            print("Need to update row #" + str(source_row.row_number))

            # Build new cell value
            new_cell = smart.models.Cell()
            new_cell.column_id = column_map["Remaining"]
            new_cell.value = 0

            # Build the row to update
            new_row = smart.models.Row()
            new_row.id = source_row.id
            new_row.cells.append(new_cell)

            return new_row

    return None

that I want to modify to take a specific sheet, sort by one date, sort by a secondary date, and then assign a number (rank) to each row based on the sort order. This is what I have so far but I'm unsure of how to build the actual sort specifier and then assign each row a number once the spreadsheet is sorted.

def evaluate_row_and_build_updates(source_row):
    # Find the cell and value we want to evaluate
    added_to_queue_cell = get_cell_by_column_name(source_row, "Added to Queue")
    added_to_queue_value = added_to_queue_cell.display_value

    received_date_cell = get_cell_by_column_name(source_row, "Received Date")
    received_date_value = received_date_cell.display_value

    slides_delivered_cell = get_cell_by_column_name(source_row, "Slides Delivered")
    slides_delivered_value = slides_delivered_cell.display_value

    if slides_delivered_value == "":
        if received_date_value != "":
            # TODO sort by 'added to queue date' then 'receieved date'
            sort_specifier = smartsheet.models.SortSpecifier({
                'sort_criteria': [smartsheet.models.SortCriterion({
                    'column_id': "Added to Queue",
                    'direction': 'ASCENDING'
                })]
            })

            # TODO assign spot in queue number after sorting
            new_cell = smart.models.Cell()
            new_cell.column_id = column_map["Spot in Queue"]
            new_cell.value = 1 # new cell value would be whatver number it was assigned after sorting

            # Build the row to update
            new_row = smart.models.Row()
            new_row.id = source_row.id
            new_row.cells.append(new_cell)

            return new_row

    return None


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source