* dump_timeline.pl now parses 4 parameters
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Sat, 18 Dec 2010 15:00:37 +0000 (15:00 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Sat, 18 Dec 2010 15:00:37 +0000 (15:00 +0000)
{{{
usage: dump_timeline.pl
    [user_timeline(default)|retweeted_by_me|
        [screen_name
            [number_of_pages|all
                [dump]
            ]
        ]
    ]
}}}
  * supported method => user_timeline, retweeted_by_me, mentions
  * default method is user_timeline

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@97 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

Dev/twitter/dump_timeline.pl

index 36fd046..246a1d4 100755 (executable)
@@ -15,15 +15,25 @@ use YAML::Tiny;
 use Data::Dumper;
 use Encode;
 
-if (@ARGV < 1) {
-    die "usage: $0 screen_name [number_of_pages|all [dump]]\n";
+if ($ARGV[0] && ($ARGV[0] eq '--help' || $ARGV[0] eq '-h') ) {
+    die <<EOM;
+usage: $0
+    [user_timeline(default)|retweeted_by_me|mentions
+        [screen_name
+            [number_of_pages|all
+                [dump]
+            ]
+        ]
+    ]
+EOM
 }
-my $screen_name = $ARGV[0];
-my $pages = $ARGV[1] || 1;
+my $method = $ARGV[0] || 'user_timeline';
+my $screen_name = $ARGV[1] || '';
+my $pages = $ARGV[2] || 1;
 if ($pages eq 'all') {
     $pages = -1;
 }
-my $dump = $ARGV[2] || 0;
+my $dump = $ARGV[3] || 0;
 
 my $conf = loadconf("$Bin/config.yml");
 if (! defined $conf) {
@@ -40,12 +50,25 @@ eval {
     my $page = 0;
     while ($pages - $page && $page <= 160) {
         $page++;
-        my $res = $bot->user_timeline(
-            {
-                screen_name => $screen_name,
-                page        => $page,
-            }
-        );
+        
+        my $param = ($screen_name)
+            ? { page => $page, screen_name => $screen_name, }
+            : { page => $page, }
+        ;
+    
+        my $res;
+        if ($method eq 'user_timeline') {
+            $res = $bot->user_timeline($param);
+        }
+        elsif ($method eq 'retweeted_by_me') {
+            $res = $bot->retweeted_by_me($param);
+        }
+        elsif ($method eq 'mentions') {
+            $res = $bot->mentions($param);
+        }
+        else {
+            die "$0: unknown method => $method\n";
+        }
         
         if ($dump) {
             foreach my $line (split /\n/, Dumper $res) {