Created
March 3, 2012 02:44
-
-
Save bobpp/1963946 to your computer and use it in GitHub Desktop.
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
| use strict; | |
| use warnings; | |
| use JSON; | |
| use Furl; | |
| use URI; | |
| use DateTime; | |
| use Time::Piece; | |
| use List::Util qw/min max/; | |
| my $f = Furl->new(); | |
| my $u = URI->new('http://www.perfume-global.com/api/load.php'); | |
| my $num = 500; | |
| my $page = 1; | |
| my $api_data; | |
| my %tweets_per_minutes; | |
| do { | |
| print STDERR "page $page....\n"; | |
| my $res = $f->post($u->as_string, undef, [ page_num => $page++, item_num => $num, order => 'asc' ]); | |
| croak($res->message) unless $res->is_success; | |
| $api_data = from_json($res->content); | |
| for (@{$api_data->{tweets}}) { | |
| my $time = Time::Piece->strptime($_->{timestamp}, '%Y-%m-%d %H:%M:%S'); | |
| my $date_time = DateTime->from_epoch(epoch => $time->epoch, time_zone => 'Asia/Tokyo')->truncate(to => 'minute'); | |
| $tweets_per_minutes{$date_time->epoch}++; | |
| } | |
| } while (scalar(@{$api_data->{tweets}}) >= $num); | |
| for (min(keys %tweets_per_minutes) .. max(keys %tweets_per_minutes)) { | |
| my $date = DateTime->from_epoch(epoch => $_, time_zone => 'Asia/Tokyo'); | |
| next if ($date->clone->truncate(to => 'minute')->epoch != $date->epoch); | |
| my $num = $tweets_per_minutes{$_} || 0; | |
| my $time = $date->strftime('%Y/%m/%d %H:%M:%S'); | |
| print "$time\t$num\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment