diff options
Diffstat (limited to 'tweet-archive.pl')
-rw-r--r-- | tweet-archive.pl | 89 |
1 files changed, 64 insertions, 25 deletions
diff --git a/tweet-archive.pl b/tweet-archive.pl index 6e007d3..1a7232b 100644 --- a/tweet-archive.pl +++ b/tweet-archive.pl @@ -1,10 +1,13 @@ #!/usr/bin/env perl -use 5.024; +use v5.36; use strict; use warnings; -use Path::Class; +use experimental 'try'; +use lib 'lib','local/lib/perl5'; +use Path::Tiny; use JSON::MaybeXS; use Dakkar::TweetArchive; +use Dakkar::NotesArchive; use Dakkar::TweetArchive::Store; my $json_parser = JSON::MaybeXS->new( @@ -13,34 +16,70 @@ my $json_parser = JSON::MaybeXS->new( ); my $conf = $json_parser->decode( - file(__FILE__)->parent->file('tweet-archive.conf') - ->slurp(iomode=>'<:raw') - // '{}' - ); + do { + try { + path(__FILE__)->sibling('tweet-archive.conf')->slurp_raw() + } + catch ($e) { + '{}' + } + }, +); + +my $store = Dakkar::TweetArchive::Store->new($conf->{db}); + +if ($conf->{twitter}) { + my $client = Dakkar::TweetArchive->new($conf->{twitter}); -my $client = Dakkar::TweetArchive->new($conf); -my $store = Dakkar::TweetArchive::Store->new($conf); + my @responses; + $client->client->ua->add_handler( response_done => sub { push @responses, $_[0]; return } ); -my $ua = $client->client->ua; -my @responses; -$ua->add_handler( response_done => sub { push @responses, $_[0]; return } ); + try { + my $latest_id = $store->latest_tweet_id; -eval { - my $latest_id = $store->latest_tweet_id; + for my $tweet ($client->home_timeline($latest_id)->@*) { + $store->store_tweet($tweet); + } - for my $tweet ($client->home_timeline($latest_id)->@*) { - $store->store_tweet($tweet); + $store->store_twitter_friends($client->friends); + $store->store_twitter_followers($client->followers); } + catch ($e) { + print "Twitter Fail: $e\n"; + for my $res (@responses) { + next if $res->is_success; + print $res->request->as_string; + print $res->as_string; + print "\n",'-' x 50,"\n\n"; + } + } + ; +}; - $store->store_friends($client->friends); - $store->store_followers($client->followers); - 1; -} or do { - print "Fail: $@\n"; - for my $res (@responses) { - next if $res->is_success; - print $res->request->as_string; - print $res->as_string; - print "\n",'-' x 50,"\n\n"; +if ($conf->{misskey}) { + my $client = Dakkar::NotesArchive->new($conf->{misskey}); + + my @responses; + $client->client->ua->add_handler( response_done => sub { push @responses, $_[0]; return } ); + + try { + my $latest_id = $store->latest_note_id; + + for my $note ($client->timeline($latest_id)->@*) { + $store->store_note($note); + } + + $store->store_misskey_following($client->following); + $store->store_misskey_followers($client->followers); } + catch ($e) { + print "Misskey Fail: $e\n"; + for my $res (@responses) { + next if $res->is_success; + print $res->request->as_string; + print $res->as_string; + print "\n",'-' x 50,"\n\n"; + } + }; }; + |