-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
84 lines (72 loc) · 2.47 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import vk
import time
import re
token = ''
session = vk.Session(access_token = token)
api = vk.API(session)
fLink = input('Ссылка на пост: ')
res = re.search(r'-\d*_\d*', fLink)
link = res.group(0)
ownerId, wallId = link.split('_')
# Если впереди стоит минус, то это паблос, для использования нам нужна переменная с минусом (ownerId) и без (groupId)
if ownerId[0] == '-':
groupId = ownerId[1:]
# Забираем ID опроса
wall = api.wall.getById(posts = link, v = 5.64)
attachments = wall[0]['attachments']
for attachment in attachments:
if attachment['type'] == 'poll':
pollId = attachment['poll']['id']
members = attachment['poll']['answers'] # участники опроса
dataOfPolls = api.polls.getById(owner_id = ownerId, poll_id = pollId, v = 5.64)
question = dataOfPolls['question']
answers = []
for answer in dataOfPolls['answers']:
answers.append(answer['text'])
# Создаем массив подписоты
offset = 0
usersOfGroup = []
print('Обрабатываем подписчиков: ')
while True:
res = api.groups.getMembers(group_id = groupId, offset = offset, v = 5.64)
usersOfGroup.extend(res['items'])
if offset % 10000 == 0:
print(len(usersOfGroup))
offset += 1000
time.sleep(0.4)
if res['count'] == len(usersOfGroup):
break
print(len(usersOfGroup))
# Создаем массив участников (id)
memberIds = []
for member in members:
memberIds.append(member['id'])
membersCount = len(memberIds)
answerIds = ','.join(map(str, memberIds))
# Создаем массив проголосовавших
votersIds = [[] for i in range(membersCount)]
isEmpty = False
offset = 0
while not isEmpty:
voters = api.polls.getVoters(owner_id = ownerId, poll_id = pollId, count = 1000, offset = offset, answer_ids = answerIds, v = 5.64)
empty = 0
for i in range(membersCount):
if len(voters[i]['users']['items']) == 0:
empty += 1
else:
votersIds[i].extend(voters[i]['users']['items'])
if empty == membersCount:
isEmpty = True
offset += 1000
time.sleep(0.4)
print(question)
print('--------------------------------')
for i in range(membersCount):
print('{0}. {1}'.format(i+1, answers[i]))
print('Количество проголосовавших - ', len(votersIds[i]))
tmp = 0
for voter in votersIds[i]:
if voter in usersOfGroup:
tmp += 1
print('Из них состоят в группе - ', tmp)
print('--------------------------------')