Я использовал функцию get для импорта данных из Airtable, но мне нужно сделать записи, которые я сортирую, так есть ли вообще создать kwarg, который может сортировать результаты в python? Идея была сделана в github, но я не мог ее понять
Код Github:
class SortParam(_BaseObjectArrayParam):
"""
Sort Param
Kwargs:
``sort=``
Specifies how the records will be ordered. If you set the view
parameter, the returned records in that view will be sorted by these
fields.
If sorting by multiple columns, column names can be passed as a list.
Sorting Direction is ascending by default, but can be reversed by
prefixing the column name with a minus sign ``-``, or passing
``COLUMN_NAME, DIRECTION`` tuples. Direction options
are ``asc`` and ``desc``.
Usage:
>>> airtable.get(sort='ColumnA')
Multiple Columns:
>>> airtable.get(sort=['ColumnA', '-ColumnB'])
Explicit Directions:
>>> airtable.get(sort=[('ColumnA', 'asc'), ('ColumnB', 'desc')])
Args:
fields (``str``, ``list``): Name of columns and directions.
"""
# Class Input > Output
# >>> filter = SortParam([{'field': 'col', 'direction': 'asc'}])
# >>> filter.to_param_dict()
# {'sort[0]['field']: 'col', sort[0]['direction']: 'asc'}
param_name = "sort"
kwarg = param_name
def __init__(self, value):
# Wraps string into list to avoid string iteration
if hasattr(value, "startswith"):
value = [value]
self.value = []
direction = "asc"
for item in value:
if not hasattr(item, "startswith"):
field_name, direction = item
else:
if item.startswith("-"):
direction = "desc"
field_name = item[1:]
else:
field_name = item
sort_param = {"field": field_name, "direction": direction}
self.value.append(sort_param)