Постер статуса Вконтакте в Твиттер

#!/usr/bin/perl -w
use strict;
use Digest::MD5 qw (md5_hex);
use WWW::Curl::Easy;
use URI::Escape;
use Carp qw[croak];
use Text::Iconv;

my $twitter_login = q[skazkin];
my $twitter_password = q[];

my $vkontakte_login = q[e@mail];
my $vkontakte_password = q[];

my $tmp_file = q[/tmp/v2t.tmp];

my $converter = Text::Iconv->new (q[windows-1251], qq[UTF8]);
my $check_hash = q[];
if (-e $tmp_file){
open FF, qq[<$tmp_file];
$check_hash = ;
close FF;
}
my $data = getURL (
{
href => q[http://vkontakte.ru/login.php],
referer => q[http://vkontakte.ru/index.php],
headers_list => [
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With: XMLHttpRequest',
'Cookie: remixlang=0; remixchk=5'
],
post => qq[op=a_login_attempt&email=$vkontakte_login&pass=$vkontakte_password&expire=0]
}
);
my ($id, @cookies, $status);
$id = $1 if $data->{content} =~ /good (\d+)/;
croak q[Can not login!\n] if !$id;
while ($data->{content} =~ /set\-cookie:([^;]+)/ig){
push (@cookies,$1);
}
croak q[No cookies] if $#cookies == -1;
$data = getURL (
{
href => qq[http://vkontakte.ru/id$id],
cookie => join («;»,@cookies)
}
);
$status = $1 if $data->{content} =~ /activity_editor\.setup\(«([^"]+)»\)/i;
croak q[No status!\n] if !$status;
croak q[Length exceed!\n] if length $status > 140;
if (md5_hex ($status) ne $check_hash){
open FF,">$tmp_file";
print FF md5_hex ($status);
close FF;
$status = $converter->convert ($status);
$data = getURL (
{
href => q[http://twitter.com/statuses/update.xml],
post => q[status=].uri_escape ($status),
user_auth => qq[$twitter_login:$twitter_password]
}
);
print qq[http://twitter.com/$twitter_login/status/$1\n] if $data->{content} =~ /(\d+)/;
exit;
}
else{
print qq[Similar status!\n];
exit;
}
print qq[Cannot post to twitter!\n];
sub getURL {
my $params = shift;
my ($result, $retcode, $curl) = ('false',undef,undef);
$curl = new WWW::Curl::Easy;
$curl->setopt (CURLOPT_URL, $params->{href});
$curl->setopt (CURLOPT_USERAGENT, q[Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2]);
$curl->setopt (CURLOPT_USERPWD, $params->{user_auth}) if $params->{user_auth};
$curl->setopt (CURLOPT_HTTPHEADER, $params->{headers_list}) if $params->{headers_list};
$curl->setopt (CURLOPT_REFERER, $params->{referer}) if $params->{referer};
$curl->setopt (CURLOPT_FOLLOWLOCATION,1);
$curl->setopt (CURLOPT_HEADER, 1);
$curl->setopt (CURLOPT_COOKIE, $params->{cookie}) if $params->{cookie};
$curl->setopt (CURLOPT_POST, 1) if $params->{post};
$curl->setopt (CURLOPT_POSTFIELDS, $params->{post}) if $params->{post};
open (my $tmp_for_curl, ">", \$result);
$curl->setopt (CURLOPT_FILE,$tmp_for_curl);
$retcode = $curl->perform;
return {retcode => $retcode, content => $result};
}

Комментировать

Войдите чтобы оставить комментарий.