Skip to content

Instantly share code, notes, and snippets.

@CubexX
Created December 19, 2017 14:01
Show Gist options
  • Save CubexX/293f33e17d313cc8093477698130d5ef to your computer and use it in GitHub Desktop.
Save CubexX/293f33e17d313cc8093477698130d5ef to your computer and use it in GitHub Desktop.
Get urls of all photo attachments from conversation
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