Created
January 28, 2013 19:55
-
-
Save proton/4658479 to your computer and use it in GitHub Desktop.
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
#encoding utf-8 | |
require 'vkontakte_api' | |
TOKEN = '' | |
#https://oauth.vk.com/authorize?client_id=3389744&scope=photos,offline&redirect_uri=http://oauth.vk.com/blank.html&display=page&response_type=token | |
vk = VkontakteApi::Client.new | |
group = vk.groups.getById(gid: 'liptonicetea').first | |
albums = vk.photos.getAlbums(gid: group.gid) | |
max_activity = -1 | |
top_album = nil | |
albums.each do |album| | |
photos = vk.photos.get(gid: group.gid, aid: album.aid, extended: 1) | |
activity = photos.reduce(0){|sum, p| sum+p.likes['count'].to_i+p.comments['count'].to_i} | |
if activity>max_activity | |
max_activity=activity | |
top_album = album | |
end | |
end | |
return unless top_album | |
users_activity = {} | |
photos = vk.photos.get(gid: group.gid, aid: top_album.aid) | |
likes | |
photos.each do |photo| | |
users = [] | |
offset = 0 | |
loop do | |
u_likes = vk.likes.getList(type: 'photo', item_id: photo.pid, owner_id: photo.owner_id, count: 1000, offset: offset) #count: 1000 - максимум | |
users += u_likes.users | |
break unless u_likes['count'].to_i==1000 | |
offset += 1 | |
end | |
users.each do |uid| | |
users_activity[uid] = 0 unless users_activity[uid] | |
users_activity[uid]+=1 | |
end | |
end | |
vk = VkontakteApi::Client.new(TOKEN) | |
#comments | |
photos.each do |photo| | |
#likes | |
users = [] | |
offset = 0 | |
loop do | |
u_comments = vk.photos.getComments(pid: photo.pid, owner_id: photo.owner_id, count: 100, offset: offset) #count: 1000 - максимум | |
puts u_comments.inspect | |
sleep(0.4) | |
users += u_comments.select{|c| c.is_a? Hashie::Mash}.map{|c| c.from_id} | |
break unless u_comments.first.to_i==100 | |
offset += 1 | |
end | |
users.each do |uid| | |
users_activity[uid] = 0 unless users_activity[uid] | |
users_activity[uid]+=1 | |
end | |
end | |
top_user_activity = users_activity.max_by{|k,v| v} | |
top_user_id = top_user_activity.first | |
puts top_user_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment