-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_new.pm
More file actions
executable file
·58 lines (46 loc) · 1.77 KB
/
get_new.pm
File metadata and controls
executable file
·58 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
#Script pulls latest 50 tweets from the bot user's home_timeline, which includes all tweets from
#all dudes that are being followed.
#Does not rely on the T_B.pm backfilling/updating module.
use strict;
use 5.010;
use warnings;
use YAML::XS qw/LoadFile/;
use DBI;
use Net::Twitter::Lite::WithAPIv1_1;
use Getopt::Std qw /getopts/;
my $dbh = DBI->connect("dbi:SQLite:dbname=twitter.db","","");
#insert preparation
my $insert_query = "INSERT INTO tweets (id, user, text) VALUES (?, ?, ?)";
my $insert_sth = $dbh->prepare($insert_query);
#this spams the dickens out of stderr because it just attempts to store all pulled
#data into the table, despite the ID key being duplicate most of the time.
sub store_tweet {
my $status = shift;
$insert_sth->execute($status->{id},lc $status->{user}->{screen_name}, $status->{text});
#say $status->{id} . " - " . $status->{text};
}
binmode STDOUT, ":utf8"; #required for STDOUT of some non-english characters
#load twitter config
our($opt_s);
getopts('s:');
my $config = defined $opt_s ? $opt_s : "config.yaml";
my ($settings) = LoadFile($config);
my $nt = Net::Twitter::Lite::WithAPIv1_1->new(
consumer_key => $settings->{consumer_key},
consumer_secret => $settings->{consumer_secret},
access_token => $settings->{access_token},
access_token_secret => $settings->{access_token_secret}
);
#my $query = "SELECT id FROM tweets WHERE user= ? ORDER BY ID DESC LIMIT 1";
#my $sth = $dbh->prepare($query);
my $latest = $dbh->selectrow_array("SELECT id FROM tweets ORDER BY ID DESC LIMIT 1");
print $latest."\n";
eval {
my $statuses = $nt->home_timeline({ since_id => $latest, exclude_replies => 1, });
for my $status (@$statuses) {
&store_tweet( $status );
}
};
$insert_sth->finish;
$dbh->disconnect;