Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
from requests import get, post
from urllib.parse import urljoin
from time import sleep
access_token='d56***2f'
def api(method, params=None, **kw):
params=dict(params or {})
params.update(kw)
params.update({
'v': '5.10',
'access_token': access_token
})
endpoint=urljoin('https://api.vk.com/method/', method)
sleep(0.3)
r=post(endpoint, data=params)
return r.json()
# r=api('photos.getAlbums',need_system=1)
# print(r)
# -15 - сохраненные фотографии
offset = 0
count = 100
photos = []
while True:
r = api('photos.get', offset=offset, count=count, album_id=-15)
print(r)
photos += r['response']['items']
offset += count
if offset >= r['response']['count']:
break
print(photos)
from pathlib import Path
import os
p=Path('/home/sergey/.vk/photos/saved')
p.mkdir(parents=True, exist_ok=True)
for photo in photos:
for k, v in photo.items():
if k.startswith('photo_'):
print('save', v)
r=get(v)
with open(str(p / os.path.basename(v)), 'wb') as f:
f.write(r.content)
r=api('photos.delete', photo_id=photo['id'])
print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.