Skip to content

Instantly share code, notes, and snippets.

@chris-x86-64
Last active December 18, 2015 20:59
Show Gist options
  • Save chris-x86-64/5843989 to your computer and use it in GitHub Desktop.
Save chris-x86-64/5843989 to your computer and use it in GitHub Desktop.
Used in conjunction with Saitan-bot. This populates initial tweet data in saitan.db.
#!/usr/bin/perl
use strict;
use warnings;
use Encode;
use utf8;
use Data::Dumper;
use AnyEvent::Twitter::Stream;
use YAML::Syck;
use lib './lib';
use SaitanBot::Database;
my $conf = YAML::Syck::LoadFile('config.yml');
my $oauth = $conf->{oauth};
my $sqlite = $conf->{sqlite};
my $saitan = SaitanBot::Database->new($sqlite);
my $done = AE::cv;
my $stream = AnyEvent::Twitter::Stream->new(
token => $oauth->{access_token},
token_secret => $oauth->{access_token_secret},
consumer_key => $oauth->{consumer_key},
consumer_secret => $oauth->{consumer_secret},
ANYEVENT_TWITTER_STREAM_SSL => 1,
method => "userstream",
on_connect => sub {
},
on_tweet => sub {
my $tweet = shift;
return unless ($tweet->{id});
print Dumper($saitan->store_tweet_to_db($tweet,
{
table => 'tweets',
column => 'text'
}
)
);
},
on_event => sub {
},
on_error => sub {
my $error = shift;
warn "Error: $error\n";
$done->send;
},
on_eof => sub {
$done->send;
},
);
$done->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment