trunk
Rev | Line | |
---|
[4e0b0a1] | 1 | #! /usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use utf8; |
---|
| 6 | |
---|
| 7 | ## IMPORTANT ## |
---|
| 8 | # When Net::Twitter::Lite encounters a Twitter API error or a network error, |
---|
| 9 | # it throws a Net::Twitter::Lite::Error object. |
---|
| 10 | # You can catch and process these exceptions by using eval blocks and testing $@ |
---|
| 11 | ## from http://search.cpan.org/perldoc?Net::Twitter::Lite#ERROR_HANDLING |
---|
| 12 | use Net::Twitter::Lite; |
---|
[6da7e2a] | 13 | use Data::Dumper; |
---|
[4e0b0a1] | 14 | |
---|
[43d739e] | 15 | my $bot = Net::Twitter::Lite->new( |
---|
| 16 | legacy_lists_api => 0, |
---|
| 17 | ); |
---|
[4e0b0a1] | 18 | |
---|
[679d34a] | 19 | my $dump; |
---|
| 20 | if (defined $ARGV[0] and $ARGV[0] eq "-d") { |
---|
| 21 | $dump = shift @ARGV; |
---|
| 22 | } |
---|
| 23 | |
---|
[4e0b0a1] | 24 | eval { |
---|
| 25 | foreach my $id (@ARGV) { |
---|
[679d34a] | 26 | $id =~ /\/?(\d+)$/; |
---|
| 27 | $id = $1; |
---|
[4e0b0a1] | 28 | my $res = $bot->show_status($id); |
---|
[035465b] | 29 | foreach my $line (split /\n/, Dumper $res) { |
---|
| 30 | if ($line =~ /undef/) { next; } |
---|
[679d34a] | 31 | if (! $dump) { |
---|
| 32 | unless ($line =~ / => {/ |
---|
| 33 | || $line =~ / = / |
---|
| 34 | || $line =~ /status/ |
---|
| 35 | || $line =~ /'text'/ |
---|
| 36 | || $line =~ /created/ |
---|
| 37 | || $line =~ /'id'/ |
---|
| 38 | || $line =~ /name/ |
---|
| 39 | || $line =~ / },/ |
---|
| 40 | || $line =~ / };/ |
---|
| 41 | ) { next; } |
---|
| 42 | } |
---|
[035465b] | 43 | print $line, "\n"; |
---|
| 44 | } |
---|
[4e0b0a1] | 45 | } |
---|
| 46 | }; |
---|
| 47 | if ($@) { |
---|
| 48 | evalrescue($@); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | sub evalrescue { |
---|
| 53 | # output error message at eval error |
---|
| 54 | |
---|
| 55 | use Scalar::Util qw(blessed); |
---|
| 56 | |
---|
| 57 | if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) { |
---|
| 58 | warn $@->error; |
---|
| 59 | if ($@->twitter_error) { |
---|
| 60 | my %twitter_error = %{$@->twitter_error}; |
---|
| 61 | map { |
---|
| 62 | $twitter_error{"$_ => "} = $twitter_error{$_} . "\n"; |
---|
| 63 | delete $twitter_error{$_} |
---|
| 64 | } keys %twitter_error; |
---|
| 65 | warn join("", %twitter_error); |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | else { |
---|
| 69 | warn $@; |
---|
| 70 | } |
---|
| 71 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.