Last active
December 19, 2015 23:59
-
-
Save tomcha/6038226 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
binmode STDOUT,":utf8"; | |
use Net::Twitter::Lite::WithAPIv1_1; | |
use Time::Piece; | |
use Time::Seconds; | |
my $twitterid; | |
my $nowtime = localtime; | |
my $fh; | |
my $datafile = qq{config.dat}; | |
unless(-e $datafile){ | |
open $fh,">",$datafile or die $!; | |
close $fh; | |
} | |
open $fh,"<",$datafile or die $!; | |
my %config; | |
my @entries= <$fh>; | |
close $fh; | |
for my $item(@entries){ | |
chomp($item); | |
my($key,$val)=split(":",$item); | |
$config{$key} = $val; | |
}; | |
my $nt = Net::Twitter::Lite::WithAPIv1_1->new( | |
consumer_key => $config{Consumerkey}, | |
consumer_secret => $config{Consumersecret}, | |
apiurl => 'https://api.twitter.com/1.1', | |
searchapiurl => 'https://api.twitter.com/1.1', | |
legacy_lists_api => 0, | |
); | |
$nt->access_token($config{Accesstoken}); | |
$nt->access_token_secret($config{Accesstokensecret}); | |
my $res = $nt->user_timeline({ user_id => $config{targetid}, count => 1000}); | |
my @tweettime; | |
for my $status(@$res){ | |
push (@tweettime,$status->{created_at}); | |
}; | |
@tweettime = reverse(@tweettime); | |
my @timediff; | |
my %timelist; | |
my $keytime; | |
for (my $tweet_index = 0;$tweet_index<@tweettime;$tweet_index++){ | |
my $time1 = localtime(Time::Piece->strptime($tweettime[$tweet_index],'%a %b %d %H:%M:%S %z %Y')); | |
my $time2 = localtime(Time::Piece->strptime($tweettime[$tweet_index-1],'%a %b %d %H:%M:%S %z %Y')); | |
my $localtime_add = Time::Seconds->new(60*60*9); | |
$time1 += $localtime_add; | |
$time2 += $localtime_add; | |
if ($tweet_index == 0){ | |
$keytime = $time1->strftime('%Y-%m-%d %H:%M:%S'); | |
}elsif(($time1-$time2) > 3*60){ | |
$keytime = $time1->strftime('%Y-%m-%d %H:%M:%S'); | |
}; | |
push (@{$timelist{$keytime}},$time1); | |
}; | |
my $maxtime = '1900-01-01 00:00:00'; | |
for my $key (sort keys %timelist){ | |
if ($maxtime lt $key){$maxtime = $key}; | |
my $tweettime = $timelist{$key}[-1]-$timelist{$key}[0]; | |
my @tweetcount = @{$timelist{$key}}; | |
my $tweet_coefficient; | |
if(scalar(@tweetcount)>10){ | |
$tweet_coefficient = scalar(@tweetcount)**2; | |
}else{ | |
$tweet_coefficient = scalar(@tweetcount); | |
} | |
if($tweettime != 0 && scalar(@tweetcount>3)){ | |
my $moz = sprintf("%.3f",$tweet_coefficient/($tweettime/1000)); | |
print "開始時刻:".$key." 連続ツイート数:".scalar(@tweetcount)." ツイート時間:".$tweettime." => ".$moz."nion\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment