Created
April 9, 2014 12:23
-
-
Save goloveychuk/10263324 to your computer and use it in GitHub Desktop.
votes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rack