Changeset 6da7e2a in lab.git


Ignore:
Timestamp:
Oct 2, 2010 10:02:23 PM (13 years ago)
Author:
mitty <mitty@…>
Branches:
master, trunk
Children:
b4d59be
Parents:
439448c
Message:
  • show_status doesn't need login

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • twitter/show_status.pl

    r035465b r6da7e2a  
    1111## from http://search.cpan.org/perldoc?Net::Twitter::Lite#ERROR_HANDLING 
    1212use Net::Twitter::Lite; 
    13 use FindBin qw($Bin); 
    14 use YAML::Tiny; 
     13use Data::Dumper; 
    1514 
    16 my $conf = loadconf("$Bin/config.yml"); 
    17 if (! defined $conf) { 
    18     die "$0: cannot parse config file.\n"; 
    19 } 
    20  
    21 my $bot = login($conf); 
    22 if (! $bot->authorized) { 
    23     die "$0: this client is not yet authorized.\n"; 
    24 } 
    25  
     15my $bot = Net::Twitter::Lite->new; 
    2616 
    2717eval { 
    2818    foreach my $id (@ARGV) { 
    2919        my $res = $bot->show_status($id); 
    30         use Data::Dumper; 
    3120        foreach my $line (split /\n/, Dumper $res) { 
    3221            if ($line =~ /undef/) { next; } 
     
    5140 
    5241 
    53 sub loadconf { 
    54     # load configration data from yaml formatted file 
    55     #   param   => scalar string of filename 
    56     #   ret     => hash object of yaml data 
    57      
    58     my $file = shift @_; 
    59      
    60     my $yaml = YAML::Tiny->read($file); 
    61      
    62     if ($!) { 
    63         warn "$0: '$file' $!\n"; 
    64     } 
    65      
    66     return $yaml->[0]; 
    67 } 
    68  
    69 sub login { 
    70     # make Net::Twitter::Lite object and login 
    71     #   param   => hash object of configration 
    72     #   ret     => Net::Twitter::Lite object 
    73      
    74     my $conf = shift @_; 
    75      
    76     my $bot = Net::Twitter::Lite->new( 
    77         consumer_key    => $conf->{consumer_key}, 
    78         consumer_secret => $conf->{consumer_secret}, 
    79     ); 
    80      
    81     $bot->access_token($conf->{access_token}); 
    82     $bot->access_token_secret($conf->{access_token_secret}); 
    83      
    84     return $bot; 
    85 } 
    86  
    8742sub evalrescue { 
    8843    # output error message at eval error 
Note: See TracChangeset for help on using the changeset viewer.