X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=Dev%2Ftwitter%2Fdump_timeline.pl;h=48a1412fab8784e67ca0eb9e0d49762e64cf0844;hb=c1b8ad4f4aa627d9318108dba6f0f54c472e8565;hp=246a1d49c31560f1dd44eeaf1b1abbc4c98afbd3;hpb=f1b126ae0a301c7164a1cbc401d79a0e49a5c215;p=lab.git diff --git a/Dev/twitter/dump_timeline.pl b/Dev/twitter/dump_timeline.pl index 246a1d4..48a1412 100755 --- a/Dev/twitter/dump_timeline.pl +++ b/Dev/twitter/dump_timeline.pl @@ -15,10 +15,10 @@ use YAML::Tiny; use Data::Dumper; use Encode; -if ($ARGV[0] && ($ARGV[0] eq '--help' || $ARGV[0] eq '-h') ) { +my $help = sub { die <authorized) { - die "$0: this client is not yet authorized.\n"; + die "$0: this client is not yet authorized."; } eval { my $page = 0; - while ($pages - $page && $page <= 160) { + while ($pages - $page && $page <= 20) { $page++; my $param = ($screen_name) - ? { page => $page, screen_name => $screen_name, } - : { page => $page, } + ? { page => $page, screen_name => $screen_name, count => 200, } + : { page => $page, count => 200, } ; my $res; - if ($method eq 'user_timeline') { + if ($method eq 'user_timeline' || $method eq 'u') { $res = $bot->user_timeline($param); } - elsif ($method eq 'retweeted_by_me') { + elsif ($method eq 'retweeted_by_me' || $method eq 'r') { $res = $bot->retweeted_by_me($param); } - elsif ($method eq 'mentions') { + elsif ($method eq 'mentions' || $method eq 'm') { $res = $bot->mentions($param); } + elsif ($method eq 'search' || $method eq 's') { + my $key; + foreach my $word (@{ $conf->{hashtag} }) { + if ($key) { + $key .= " OR $word"; + } + else { + $key = $word; + } + } + $param->{q} = $key; + $res = $bot->search($param)->{results}; + } else { - die "$0: unknown method => $method\n"; + warn "$0: unknown method '$method'"; + &{$help}; } if ($dump) { @@ -79,12 +97,16 @@ eval { else { foreach my $status (@{$res}) { my $text = ""; - $text .= $status->{user}{name}; + $text .= "(". $status->{id} . ") "; + $text .= ($status->{user}{screen_name}) ? + $status->{user}{screen_name} : $status->{from_user}; + $text .= "|"; + $text .= ($status->{user}{name}) ? + $status->{user}{name} : $status->{from_user_name}; $text .= " [" . $status->{created_at} . "]"; - $text .= " (". $status->{id} . ")"; - $text .= " ". encode('utf8', $status->{text}); + $text .= " ". $status->{text}; $text =~ s/\n//; - print $text, "\n"; + print encode('utf8', $text), "\n"; } } } @@ -92,7 +114,6 @@ eval { if ($@) { evalrescue($@); } -print "done\n"; sub loadconf { @@ -105,7 +126,7 @@ sub loadconf { my $yaml = YAML::Tiny->read($file); if ($!) { - warn "$0: '$file' $!\n"; + warn "$0: '$file' $!"; } return $yaml->[0]; @@ -121,6 +142,7 @@ sub login { my $bot = Net::Twitter::Lite->new( consumer_key => $conf->{consumer_key}, consumer_secret => $conf->{consumer_secret}, + legacy_lists_api => 0, ); $bot->access_token($conf->{access_token});