-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8_task.py
More file actions
69 lines (63 loc) · 2.21 KB
/
Copy path8_task.py
File metadata and controls
69 lines (63 loc) · 2.21 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import requests
import json
import re
import time
key = "&access_token="
v = "&v=5.103"
link = "https://api.vk.com/method/"
friends_list = "friends.get?count=10000&user_id="
url_to_id = "utils.resolveScreenName?screen_name="
users_get = "users.get?fields=sex,bdate,city,country&user_ids="
count_lines = 300
def get_id(url):
url = re.search(r"vk\.com\/(.+)",url)
if(not url):
return False
user = url.group(1)
response = requests.get(link + url_to_id + user + key + v)
j = json.loads(response.text)
if("response" in j):
if("object_id" in j["response"]):
return j["response"]["object_id"]
else:
return False
else:
return False
def get_friends(uid):
response = requests.get(link + friends_list + str(uid) + key + v)
j = json.loads(response.text)
if("response" in j):
if("items" in j["response"]):
return j["response"]["items"]
def print_info(friends):
friends = [str(i) for i in friends]
friends = [friends[i:i + count_lines] for i in range(0, len(friends), count_lines)]
for part in friends:
l = ",".join(part)
response = requests.get(link+users_get+l+key+v)
j = json.loads(response.text)
if("response" in j):
for i in j["response"]:
first = i["first_name"]
last = i["last_name"]
u_id = i["id"]
bdate = ""
country = ""
city = ""
if ("bdate" in i):
bdate = i["bdate"]
if ("country" in i):
country = i["country"]["title"]
if ("city" in i):
city = i["city"]["title"]
result = "{0:15} {1:20} {2:15} {3:15} {4:20} vk.com/{5}".format(first, last, bdate, country, city, u_id)
print(result)
if __name__ == "__main__":
key += input("Введите сервисный ключ: ")
url = input("Введите ссылку на пользователя: ")
user_id = get_id(url)
if(not user_id):
print("Неверная ссылка на пользователя")
exit(0)
friends = get_friends(user_id)
print_info(friends)