I
I
Irina2018-08-21 02:33:29
Python
Irina, 2018-08-21 02:33:29

How to get the necessary data from MessageEntity (Telegram bot, Python)?

I have an object. about like this.

call.message= {'content_type': 'text', 
                                                           'message_id': 3704, 
                                                           'from_user': {'id': 000000000, 
                                                                               'is_bot': True,
                                                                               'first_name': 'testbot',
                                                                               'username': 'test_bot', 
                                                                               'last_name': None, 
                                                                                'language_code': None},
                                                            'date': 1534805095,
                                                            'chat': {'type': 'private', 
                                                                      'last_name': None, 
                                                                       'first_name': 'Myza', 
                                                                       'username': 'vera_ira',
                                                                       'id': 000000000,
                                                                       'title': None, 
                                                                       'all_members_are_administrators': None,
                                                                       'photo': None},
                                                            ....   ....
                                                           'json': {'message_id': 3704, 
                                                                      'from': {'id': 000000000,
                                                                                  'is_bot': True,
 	                                                                          'first_name': 'Irisbot',
                                                                                  'username': 'Via00000000000_bot'}, 
                                                                       'chat': {'id': 000000000, 
                                                                                 'first_name': 'Myza',
                                                                                  'username': 'vera_ira',
 	                                                                          'type': 'private'}, 
                                                                       'date': 1534805095, 
                                                                       'text': 'тттт ттттттттт ттттт тт т тттттт тттт ооооооо ттт тттт ттт.', 
                                                                        'entities': [{'offset': 32, 'length': 7, 'type': 'bold'}]}}

How to get 32 ​​and 7 from it (from the last line). I use:
print(call.message.json.entities.offset)
print(call.message.json.entities.length)

Issues:
AttributeError: 'dict' object has no attribute 'entities'

But at the same time, call.message.json prints without errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bobsans, 2018-08-21
@vera_ira

Try or

print(call.message.json.get('entities')[0].get('offset'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question