Changeset 61 in lab


Ignore:
Timestamp:
Oct 4, 2010 9:18:30 PM (13 years ago)
Author:
mitty
Message:
  • change structure of return value from or_search, mentions_ids
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/twitter/twitterbot.pl

    r60 r61  
    3434} 
    3535 
    36 my %tweets; 
     36my $tweets = {}; 
    3737my $tweet; 
    3838 
    3939$tweet = or_search($bot, $conf->{hashtag}, $stat->{search}); 
    4040if ($tweet) { 
    41     %tweets = (%tweets, %$tweet); 
     41    %$tweets = (%$tweets, %$tweet); 
    4242} 
    4343 
    4444$tweet = mentions_ids($bot, $stat->{mention}); 
    4545if ($tweet) { 
    46     %tweets = (%tweets, %$tweet); 
    47 } 
    48  
    49 foreach my $id (sort keys %tweets) { 
    50     if ($tweets{$id} eq 'retweet') { 
     46    %$tweets = (%$tweets, %$tweet); 
     47} 
     48 
     49foreach my $id (sort keys %$tweets) { 
     50    # $tweets->{$id}{type} eq 'search'  => found by search API 
     51    #                      eq 'mention' => found by mention API 
     52    if ($tweets->{$id}{type} eq 'retweet') { 
    5153        next; 
    5254    } 
    5355    DEBUG or sleep($conf->{sleep}); 
    54     # retweet found tweet 
    55     #   $tweets->{$id} eq 'search'  => found by search API 
    56     #                  eq 'mention' => found by mention API 
     56     
     57    # do retweet found tweets 
    5758    my $res; 
    5859    eval { 
    5960        DEBUG  or $res = $bot->retweet($id); 
    60         DEBUG and warn "retweet($id) => ", Dumper($tweets{$id}); 
     61        DEBUG and warn "retweet($id) => ", Dumper($tweets->{$id}); 
    6162    }; 
    6263    if ($@) { 
     
    6667    } 
    6768     
    68     $stat->{$tweets{$id}} = $id; 
    69 } 
    70  
    71 if (%tweets) { 
     69    $stat->{$tweets->{$id}{type}} = $id; 
     70} 
     71 
     72if ($tweets) { 
    7273    # save last status to yaml file 
    7374    DEBUG  or YAML::Tiny::DumpFile("$Bin/status.yml", $stat); 
     
    147148                my $res = $bot->show_status($tweet->{id}); 
    148149                if ($res->{retweeted_status}) { 
    149                     $ids->{$tweet->{id}} = 'retweet'; 
     150                    $ids->{$tweet->{id}}{type} = 'retweet'; 
    150151                } 
    151152                else { 
    152                     $ids->{$tweet->{id}} = 'search'; 
     153                    $ids->{$tweet->{id}}{type} = 'search'; 
    153154                } 
    154155                VERBOSE and warn Dumper($res); 
     
    189190    if ($res && @{$res}) { 
    190191        $ids = { 
    191             map { $_->{id} => 'mention' } @{$res} 
     192            map { 
     193                $_->{id} => { 
     194                    type => 'mention', 
     195                } 
     196            } @{$res} 
    192197        }; 
    193198    } 
Note: See TracChangeset for help on using the changeset viewer.