Changeset f1b126a in lab.git for Dev/twitter/dump_timeline.pl


Ignore:
Timestamp:
Dec 19, 2010 12:00:37 AM (14 years ago)
Author:
mitty <mitty@…>
Branches:
master, trunk
Children:
fe75883
Parents:
a7e2c53
Message:
  • dump_timeline.pl now parses 4 parameters
    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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/twitter/dump_timeline.pl

    ra7e2c53 rf1b126a  
    1616use Encode; 
    1717 
    18 if (@ARGV < 1) { 
    19     die "usage: $0 screen_name [number_of_pages|all [dump]]\n"; 
     18if ($ARGV[0] && ($ARGV[0] eq '--help' || $ARGV[0] eq '-h') ) { 
     19    die <<EOM; 
     20usage: $0 
     21    [user_timeline(default)|retweeted_by_me|mentions 
     22        [screen_name 
     23            [number_of_pages|all 
     24                [dump] 
     25            ] 
     26        ] 
     27    ] 
     28EOM 
    2029} 
    21 my $screen_name = $ARGV[0]; 
    22 my $pages = $ARGV[1] || 1; 
     30my $method = $ARGV[0] || 'user_timeline'; 
     31my $screen_name = $ARGV[1] || ''; 
     32my $pages = $ARGV[2] || 1; 
    2333if ($pages eq 'all') { 
    2434    $pages = -1; 
    2535} 
    26 my $dump = $ARGV[2] || 0; 
     36my $dump = $ARGV[3] || 0; 
    2737 
    2838my $conf = loadconf("$Bin/config.yml"); 
     
    4151    while ($pages - $page && $page <= 160) { 
    4252        $page++; 
    43         my $res = $bot->user_timeline( 
    44             { 
    45                 screen_name => $screen_name, 
    46                 page        => $page, 
    47             } 
    48         ); 
     53         
     54        my $param = ($screen_name) 
     55            ? { page => $page, screen_name => $screen_name, } 
     56            : { page => $page, } 
     57        ; 
     58     
     59        my $res; 
     60        if ($method eq 'user_timeline') { 
     61            $res = $bot->user_timeline($param); 
     62        } 
     63        elsif ($method eq 'retweeted_by_me') { 
     64            $res = $bot->retweeted_by_me($param); 
     65        } 
     66        elsif ($method eq 'mentions') { 
     67            $res = $bot->mentions($param); 
     68        } 
     69        else { 
     70            die "$0: unknown method => $method\n"; 
     71        } 
    4972         
    5073        if ($dump) { 
Note: See TracChangeset for help on using the changeset viewer.