Reputation: 35
I was using get request to get some data by this code
at = airtable.Airtable('BASE_ID', 'API_KEY')
airtable_data = at.get('Table 3')
print(airtable_data)
and the results was
OrderedDict([('records', [OrderedDict([('id', 'rec3qP7SjyowO'), ('fields',OrderedDict([('User', 'User'), ('Text', 'TEST'), ('Date', '2020-01-15T13:09:03.000Z')])), ('createdTime', '2020-01-15T13:09:09.000Z')]), OrderedDict([('id', 'recOUVoNXHak'), ('fields', OrderedDict([('User', 'user'), ('Text', 'TEST'), ('Date', '2020-01-15T13:05:43.000Z')])), ('createdTime', '2020-01-15T13:08:55.000Z')])])])
then I used
airtable_list = (list(airtable_data))
print(airtable_list[0])
the results was records only and I can't find a way to extract the rest of the data
Upvotes: 1
Views: 67
Reputation: 149
The issue is that when you pass that OrderdDict
through List
, it gives you value of key
which is records
.
To display the proper data, you can use below logic.
from collections import OrderedDict
airtable_data = OrderedDict([('records', [OrderedDict([('id', 'rec3qP7SjyowO'), ('fields',OrderedDict([('User', 'User'), ('Text', 'TEST'), ('Date', '2020-01-15T13:09:03.000Z')])), ('createdTime', '2020-01-15T13:09:09.000Z')]), OrderedDict([('id', 'recOUVoNXHak'), ('fields', OrderedDict([('User', 'user'), ('Text', 'TEST'), ('Date', '2020-01-15T13:05:43.000Z')])), ('createdTime', '2020-01-15T13:08:55.000Z')])])])
for k,v in airtable_data.items():
i = 0
for data in v:
i += 1
for k1, v1 in data.items():
print(k1,'---->', v1)
print('Data displayed for item number ', i)
print('----------------------------------------------------')
print(' ')
Upvotes: 1
Reputation: 17322
since your variable airtable_data
is OrderedDict
type you can get the rest of the data by accessing the value for the key records
:
my_data = airtable_data['records']
Upvotes: 0