Python
0
Вклад в тег
import os
import vk
import datetime
import httplib2
access_token = ''
app_id = ''
def get_photo(id):
login = input('login: ')
password = input('password: ')
vkapi = vk.API(ap_id, login, password, access_token)
album = vkapi.photos.getAlbums(owner_id=id, need_system=1)
user_info = vkapi.users.get(user_ids=id)
name = str(user_info[0]['first_name']) + ' ' + str(user_info[0]['last_name'])
y, n = 0, 0
while n <= 1000:
photo = vkapi.photos.getAll(owner_id=id, count=200, offset=n)
for i in photo['items']:
for j in album['items']:
if j['id'] == i['album_id']:
if not os.path.exists("C:\\Users\\home\\Desktop\\vk_photo\\" + name + '\\' + str(j['title'])):
os.makedirs("C:\\Users\\home\\Desktop\\vk_photo\\" + name + '\\' + str(j['title']))
y += 1
print(y, [str(j['title'])], [str(i['id'])])
key = i.keys()
max_size = 0
for x in key:
if x.startswith('photo_') and (int(x[6:]) > max_size):
max_size = int(x[6:])
img = i['photo_' + str(max_size)]
date = datetime.datetime.fromtimestamp(i['date']).strftime('%Y.%m.%d-%H.%M')
h = httplib2.Http()
response, content = h.request(img)
foto = open('C:\\Users\\home\\Desktop\\vk_photo\\' + name + '\\' + str(j['title']) + '\\' + str(
y) + ' ' + date + '.jpg', 'wb')
foto.write(content)
foto.close()
n += 200
if __name__ == '__main__':
ids = input('id: ')
get_photo(ids)