* add new hash members to return value of or_search and mentions_ids
[lab.git] / twitterbot.pl
index 249c1bc..d1dd229 100755 (executable)
@@ -12,9 +12,11 @@ use utf8;
 use Net::Twitter::Lite;
 use FindBin qw($Bin);
 use YAML::Tiny;
+use Date::Parse qw(str2time);
 
-sub VERBOSE () { $ARGV[0] eq 'verbose' };
-sub DEBUG   () { VERBOSE or $ARGV[0] eq 'debug' };
+my $_execmode = $ARGV[0] || 0;
+sub VERBOSE () { $_execmode eq 'verbose' };
+sub DEBUG   () { VERBOSE or $_execmode eq 'debug' };
 use Data::Dumper;
 
 DEBUG and warn "$0: debug mode";
@@ -142,17 +144,27 @@ sub or_search {
                 }
             );
         }
+        VERBOSE and warn Dumper($res);
         if ($res->{results}) {
-            VERBOSE and warn Dumper($res);
             foreach my $tweet (@{$res->{results}}) {
                 my $res = $bot->show_status($tweet->{id});
+                VERBOSE and warn Dumper($res);
+                
+                my $id = {
+                    date        => str2time($res->{created_at}),
+                    screen_name => $res->{user}{screen_name},
+                    status_id   => $res->{id},
+                    text        => $res->{text},
+                    user_id     => $res->{user}{id},
+                };
                 if ($res->{retweeted_status}) {
-                    $ids->{$tweet->{id}}{type} = 'retweet';
+                    $id->{retweet_of}   = $res->{retweeted_status}{id};
+                    $id->{type}         = 'retweet';
                 }
                 else {
-                    $ids->{$tweet->{id}}{type} = 'search';
+                    $id->{type} = 'search';
                 }
-                VERBOSE and warn Dumper($res);
+                $ids->{$tweet->{id}} = $id;
             }
         }
     };
@@ -191,7 +203,12 @@ sub mentions_ids {
         $ids = {
             map {
                 $_->{id} => {
-                    type => 'mention',
+                    date        => str2time($_->{created_at}),
+                    screen_name => $_->{user}{screen_name},
+                    status_id   => $_->{id},
+                    text        => $_->{text},
+                    type        => 'mention',
+                    user_id     => $_->{user}{id},
                 }
             } @{$res}
         };