Skip to content

Instantly share code, notes, and snippets.

@goloveychuk
Created April 9, 2014 12:23
Show Gist options
  • Save goloveychuk/10263324 to your computer and use it in GitHub Desktop.
Save goloveychuk/10263324 to your computer and use it in GitHub Desktop.
votes
import re
from operator import __getitem__
import requests#pip install requests
from collections import Counter
from time import sleep
url = r'https://api.vk.com/method/wall.getComments'
params = {'owner_id': -23762795,
'post_id': 64220,
'count': 100,
'offset': 0,
}
votes = Counter()
ids = set()
votes_num = 0
while True:
data = requests.get(url, params=params).json()
items = data['response'][1:]
if not items:
break
for i in items:
from_id = i['from_id']
if from_id not in ids:#revoting
nums = map(int, re.findall('\d+', i['text']))
nums = filter(lambda x: x<50, nums)# filter ids in message
nums_unique = set(nums)
if len(nums_unique)==1:
votes[nums_unique.pop()]+=1
ids.add(from_id)
votes_num+=1
else:
print i['text'].encode('utf8')
params['offset'] += 100
sleep(2)
print 'results:'
for i,j in sorted(votes.items(), reverse=True, key=lambda x: __getitem__(x,1)):
print i,'-',j
print 'votes_count', votes_num
Copy link

ghost commented Apr 9, 2014

rack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment