Created
December 19, 2017 14:01
-
-
Save CubexX/293f33e17d313cc8093477698130d5ef to your computer and use it in GitHub Desktop.
Get urls of all photo attachments from conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vk_lplib import VK | |
# Used https://github.com/stroum/vk_lplib/ | |
CONVERSATION_ID = 0 | |
USER_ID = 0 | |
TOKEN = "" | |
vk = VK(USER_ID, TOKEN) | |
start_from = 0 | |
count = 200 | |
links = [] | |
while 1: | |
a = vk.api.messages.getHistoryAttachments({ | |
'peer_id': CONVERSATION_ID, | |
'media_type': 'photo', | |
'count': count, | |
'photo_sizes': 1, | |
'start_from': start_from | |
})['response'] | |
if 'next_from' in a: | |
start_from = a['next_from'] | |
i = 0 | |
while i < count: | |
link = a['items'][i]['attachment']['photo']['sizes'][-1]['src'] | |
links.append(link) | |
i += 1 | |
else: | |
break | |
with open('urls.txt', 'w') as file: | |
for link in links: | |
file.write("%s\n" % link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment