Last active
May 15, 2017 09:53
-
-
Save skar404/9d85916ff92c75e776a4c1d13a2d40cb to your computer and use it in GitHub Desktop.
This file contains 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
# -*- 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