-
Notifications
You must be signed in to change notification settings - Fork 0
/
vk_api.py
50 lines (44 loc) · 1.16 KB
/
vk_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
from settings import settings
def get_images(
owner_id: int,
album_id: int,
offset: int = 0,
count: int = 50
) -> dict:
res = requests.get(
'https://api.vk.com/method/photos.get',
params={
'access_token': settings.ACCESS_TOKEN,
'owner_id': owner_id,
'album_id': album_id,
'extended': 1,
'photo_sizes': 1,
'v': '5.131',
'offset': offset,
'count': count,
}
)
if res.status_code != 200:
raise Exception(f'{res}: {res.text}')
try:
return res.json()['response']
except:
raise Exception(f'{res}: {res.text}')
def get_users(
users_ids: list[int] | set[int]
) -> list:
res = requests.get(
'https://api.vk.com/method/users.get',
params={
'access_token': settings.ACCESS_TOKEN,
'user_ids': ','.join(map(str, users_ids)),
'v': '5.131',
}
)
if res.status_code != 200:
raise Exception(f'{res}: {res.text}')
try:
return res.json()['response']
except:
raise Exception(f'{res}: {res.text}')