forked from devmanorg/8_vk_friends_online
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvk_friends_online.py
42 lines (30 loc) · 973 Bytes
/
vk_friends_online.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
from getpass import getpass
import vk
APP_ID = 6331864
def get_user_login():
return input('Введите логин: ')
def get_user_password():
return getpass('Введите пароль: ')
def get_online_friends(login, password):
session = vk.AuthSession(
app_id=APP_ID,
user_login=login,
user_password=password,
scope='friends'
)
api = vk.API(session)
friend_ids = api.friends.getOnline()
friends = api.users.get(
user_ids=friend_ids,
fields='first_name,last_name',
)
return friends
def output_friends_to_console(friends_online):
for friend in friends_online:
print('{} {}'.format(friend['first_name'], friend['last_name']))
if __name__ == '__main__':
login = get_user_login()
password = get_user_password()
friends_online = get_online_friends(login, password)
print("Друзья онлайн:")
output_friends_to_console(friends_online)