Created
December 23, 2011 19:37
-
-
Save sergeyromanov/1515171 to your computer and use it in GitHub Desktop.
VKontakte like-counter
This file contains hidden or 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
#!perl | |
# Krivykh Alexey 2011 | |
use 5.010; | |
use strict; | |
use GD::Graph::colour; | |
use GD::Graph::hbars; | |
use HTTP::Cookies; | |
use LWP::UserAgent; | |
use Unicode::Map8; | |
die <<DIE_MSG | |
Expect two or tree parameters: | |
vk_login password [id user you want to see statistics of likes] | |
[parameter] - optional | |
DIE_MSG | |
if @ARGV < 2; | |
my ($mail, $pass) = @ARGV[0, 1]; | |
my $ua = LWP::UserAgent->new(); | |
my $cookie = HTTP::Cookies->new(); | |
$ua->cookie_jar($cookie); | |
($ua->get("http://login.vk.com/?act=login&email=$mail&pass=$pass&from_host=vk.com")->content=~/id: (\d+)/) or die('Autorization failed: invalid login or password'); | |
my $id = $ARGV[2] // $1; | |
$ua->get("http://vkontakte.ru/id$id")->content =~ m!<title>(\S+\s*\S*)</title>!; | |
my $name = $1; | |
my (@uniq, @post_id, $offset, %seen); | |
while((scalar @uniq< 50)&&(@post_id = $ua->post("http://vkontakte.ru/al_wall.php",[act=>'get_wall', al=>'1', offset=>$offset, owner_id=>$id, type=>'all'])->content =~ m!$name<\/a>.*?<div id="wpt(\d+_\d+)"!sg)) { | |
foreach(@post_id){ | |
push(@uniq, $_) unless $seen{$_}++; | |
} | |
$offset+=10; | |
} | |
my (@likeNames, $cp_map, %stat); | |
foreach(@uniq){ | |
@likeNames = ($ua->post("http://vkontakte.ru/like.php",[act=>'a_get_stats', al=>'1', object=>'wall'.$_])->content) | |
=~/<a title="(\S+\s*\S*)"/g; | |
foreach(@likeNames){ | |
$cp_map = Unicode::Map8->new('cp1251'); | |
$_ = $cp_map->tou($_); | |
$stat{$_}++; | |
} | |
} | |
GD::Graph::colour::add_colour('RoyalBlue' => [73,108,225]); | |
my $graph = GD::Graph::hbars->new(700,1000); | |
$graph->set( | |
x_label => $cp_map->tou('Names'), | |
y_label => $cp_map->tou('Likes number'), | |
title => $cp_map->tou('Likes stats'), | |
dclrs => ['RoyalBlue'], | |
show_values => 1, | |
logo => 'Logo_vk.png', | |
logo_resize => 0.15, | |
logo_position => 'UR', | |
) or die $graph->error; | |
my @graph_data = ( | |
[keys %stat], | |
[values %stat], | |
); | |
my $font_file = 'arial.ttf'; | |
$graph->set_text_clr('RoyalBlue'); | |
$graph->set_title_font($font_file, 14); | |
$graph->set_x_label_font($font_file, 14); | |
$graph->set_y_label_font($font_file, 14); | |
$graph->set_x_axis_font($font_file, 16); | |
$graph->set_y_axis_font($font_file, 14); | |
$graph->set_values_font($font_file, 14); | |
my $gd = $graph->plot(\@graph_data) or die $graph->error; | |
open my $img, '>', 'StatGraph.png' or die $!; | |
binmode $img; | |
print $img $gd->png; | |
close $img; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment