P
P
podsalyami2021-03-23 21:16:06
Python
podsalyami, 2021-03-23 21:16:06

How to pull out owner_id and photo_id values?

Hello!! I'm writing a bot that needs to overlay text on a photo that I send to him.
Through the team

txt = vk.method('messages.getHistoryAttachments', {'peer_id': 2000000000 + 1, 'media_type': 'photo', 'count': 1})

I am getting information about the message as this string
{'items': [{'message_id': 477043, 'from_id': -172196983, 'attachment': {'type': 'photo', 'photo': {'album_id': -64, 'date': 1616517671, 'id': 457247112, 'owner_id': -172196983, 'has_tags': False, 'access_key': '2079596cc22587f762', 'sizes': [{'height': 67, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 's', 'width': 75}, {'height': 117, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'm', 'width': 130}, {'height': 543, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'x', 'width': 604}, {'height': 725, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'y', 'width': 807}, {'height': 968, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'z', 'width': 1078}, {'height': 117, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'o', 'width': 130}, {'height': 180, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'p', 'width': 200}, {'height': 287, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'q', 'width': 320}, {'height': 458, 'url': 'https://sun9-24.userapi.com/impf/bbXLL5WFXfVctWFufHhD_eYv46IH..', 'type': 'r', 'width': 510}], 'text': '', 'user_id': 100}}}], 'next_from': '477043/1', 'groups': [{'id': 172196983, 'name': 'Парадокс Фарадея', 'screen_name': 'fara__228', 'is_closed': 0, 'type': 'page', 'photo_50': 'https://sun1.43222.userapi.com/s/v1/ig2/p7XJDEONgSfu33HYSzZFi..', 'photo_100': 'https://sun1.43222.userapi.com/s/v1/ig2/6slGdZYBNcqCBdhEUETPS..', 'photo_200': 'https://sun1.43222.userapi.com/s/v1/ig2/hKcBvv1ceIvinQeMUdzCQ..'}]}

How to extract the owner_id and id values ​​from this line?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy _, 2021-03-23
@podsalyami

Well cammon...

['items'][0]['attachment']['photo']['owner_id']
['items'][0]['attachment']['photo']['id']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question