Changeset 58 in lab
- Timestamp:
- Oct 4, 2010 5:03:42 PM (13 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/twitter/user_timeline.pl
r56 r58 13 13 use FindBin qw($Bin); 14 14 use YAML::Tiny; 15 use Data::Dumper; 16 use Encode; 17 18 if (@ARGV < 1) { 19 die "usage: $0 screen_name [number_of_pages|all [dump]]\n"; 20 } 21 my $screen_name = $ARGV[0]; 22 my $pages = $ARGV[1] || 1; 23 if ($pages eq 'all') { 24 $pages = -1; 25 } 26 my $dump = $ARGV[2] || 0; 15 27 16 28 my $conf = loadconf("$Bin/config.yml"); … … 26 38 27 39 eval { 28 foreach my $id (@ARGV) { 29 my $res = $bot->show_status($id); 30 use Data::Dumper; 31 foreach my $line (split /\n/, Dumper $res) { 32 if ($line =~ /undef/) { next; } 33 unless ($line =~ / => {/ 34 || $line =~ / = / 35 || $line =~ /status/ 36 || $line =~ /'text'/ 37 || $line =~ /created/ 38 || $line =~ /'id'/ 39 || $line =~ /name/ 40 || $line =~ / },/ 41 || $line =~ / };/ 42 ) { next; } 43 print $line, "\n"; 40 my $page = 0; 41 while ($pages - $page && $page <= 160) { 42 $page++; 43 my $res = $bot->user_timeline( 44 { 45 screen_name => $screen_name, 46 page => $page, 47 } 48 ); 49 50 if ($dump) { 51 foreach my $line (split /\n/, Dumper $res) { 52 if ($line =~ /undef/) { next; } 53 print $line, "\n"; 54 } 55 } 56 else { 57 foreach my $status (@{$res}) { 58 my $text = ""; 59 $text .= $status->{user}{name}; 60 $text .= " [" . $status->{created_at} . "]"; 61 $text .= " (". $status->{id} . ")"; 62 $text .= " ". encode('utf8', $status->{text}); 63 $text =~ s/\n//; 64 print $text, "\n"; 65 } 44 66 } 45 67 }
Note: See TracChangeset
for help on using the changeset viewer.