Changeset 104 in lab


Ignore:
Timestamp:
Jan 10, 2011 6:57:45 PM (13 years ago)
Author:
mitty
Message:
  • NEW send a mail
    • tweets to me and search results
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Dev/twitter/twitterbot.pl

    r103 r104  
    1414use YAML::Tiny; 
    1515use Date::Parse qw(str2time); 
     16use Mail::Sendmail; 
     17use Encode; 
    1618 
    1719my $_execmode = $ARGV[0] || 0; 
     
    5254    if ($tweets->{$id}{type} eq 'retweet') { 
    5355        DEBUG and warn "skipping $id that was already retweeted\n"; 
    54         $skip = $id; 
     56        $skip = 'retweet'; 
    5557    } 
    5658    if (defined $conf->{allow}) { 
    57         $skip = $id; 
     59        $skip = 'allow'; 
    5860        foreach my $screen_name ( @{ $conf->{allow}{screen_name} } ) { 
    5961            if ($tweets->{$id}{screen_name} eq $screen_name) { 
     
    6971                last; 
    7072            } 
     73        } 
     74    } 
     75     
     76    if (defined $conf->{mail}) { 
     77        my $send; 
     78        foreach my $pickup ( @{ $conf->{mail}{pickup} } ) { 
     79            if ($tweets->{$id}{type} eq $pickup) { 
     80                $send = 1; 
     81                last; 
     82            } 
     83        } 
     84        if ($conf->{mail}{ignore_allowed}) { 
     85            if (defined $conf->{allow} and ! defined $skip) { 
     86                # this tweet was allowed to retweet, so that be ignored on mail 
     87                undef $send; 
     88            } 
     89        } 
     90         
     91        if ($send) { 
     92            if (! exists($conf->{mail}{body}) ) { 
     93                $conf->{mail}{body} = 
     94                    "[localtime(date)] http://twitter.com/<screen_name>/status/<status_id> text\n" . 
     95                    "----------------------------------------\n" 
     96                ; 
     97            } 
     98            $conf->{mail}{body} .= 
     99                "[" . localtime($tweets->{$id}{date}) . "] " . 
     100                "http://twitter.com/" . 
     101                $tweets->{$id}{screen_name} . "/status/" . 
     102                $tweets->{$id}{status_id} . " " . 
     103                $tweets->{$id}{text} . "\n" 
     104            ; 
    71105        } 
    72106    } 
     
    91125     
    92126    $stat->{$tweets->{$id}{type}} = $id; 
     127} 
     128 
     129if ($conf->{mail}{body}) { 
     130    my $body = encode("iso-2022-jp", $conf->{mail}{body}); 
     131     
     132    my %mail = ( 
     133        Smtp            => $conf->{mail}{server}, 
     134        From            => $conf->{mail}{from}, 
     135        To              => join(", ", @{ $conf->{mail}{to} }), 
     136        Subject         => $conf->{mail}{subject}, 
     137        "Content-Type"  => $conf->{mail}{contenttype}, 
     138        Body            => $body, 
     139    ); 
     140    DEBUG and warn "sending mail => ", Dumper(\%mail); 
     141     
     142    DEBUG or sendmail(%mail) or warn "Error sending mail: $Mail::Sendmail::error\n"; 
    93143} 
    94144 
Note: See TracChangeset for help on using the changeset viewer.