Skip to content

Instantly share code, notes, and snippets.

@skar404
Last active May 15, 2017 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skar404/9d85916ff92c75e776a4c1d13a2d40cb to your computer and use it in GitHub Desktop.
Save skar404/9d85916ff92c75e776a4c1d13a2d40cb to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import requests
import vk_api
def main():
login, password = 'user@user.ru', '12345678'
vk_session = vk_api.VkApi(login, password)
try:
vk_session.authorization()
except vk_api.AuthorizationError as error_msg:
print(error_msg)
return
vk = vk_session.get_api()
list_photos = vk.fave.getPhotos(count='999', photo_sizes=0)
url_list = []
for i in list_photos['items']:
if 'photo_2560' in i:
url = i['photo_2560']
elif 'photo_1280' in i:
url = i['photo_1280']
elif 'photo_807' in i:
url = i['photo_807']
elif 'photo_604' in i:
url = i['photo_604']
elif 'photo_130' in i:
url = i['photo_130']
elif 'photo_75' in i:
url = i['photo_75']
else:
url = False
url_list.append({'url': url, 'id': i['id']})
for i in url_list:
if i['url']:
with open('./list/'+str(i['id'])+'.png', "wb") as receive:
req = requests.get(i['url'], stream=True)
for chunk in req.iter_content(1024):
receive.write(chunk)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment