From 0b356d2e192fa531fb149cfd89f9d93324a90ebe Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Wed, 22 Feb 2023 13:53:11 +0000 Subject: store misskey notes & people --- tweet-archive.pl | 72 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 20 deletions(-) (limited to 'tweet-archive.pl') diff --git a/tweet-archive.pl b/tweet-archive.pl index a1b5fff..1a7232b 100644 --- a/tweet-archive.pl +++ b/tweet-archive.pl @@ -3,9 +3,11 @@ use v5.36; use strict; use warnings; 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( @@ -24,30 +26,60 @@ my $conf = $json_parser->decode( }, ); -my $client = Dakkar::TweetArchive->new($conf); -my $store = Dakkar::TweetArchive::Store->new($conf); +my $store = Dakkar::TweetArchive::Store->new($conf->{db}); -my $ua = $client->client->ua; -my @responses; -$ua->add_handler( response_done => sub { push @responses, $_[0]; return } ); +if ($conf->{twitter}) { + my $client = Dakkar::TweetArchive->new($conf->{twitter}); -try { - my $latest_id = $store->latest_tweet_id; + my @responses; + $client->client->ua->add_handler( response_done => sub { push @responses, $_[0]; return } ); - for my $tweet ($client->home_timeline($latest_id)->@*) { - $store->store_tweet($tweet); + try { + my $latest_id = $store->latest_tweet_id; + + 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"; + } + } + ; +}; + +if ($conf->{misskey}) { + my $client = Dakkar::NotesArchive->new($conf->{misskey}); - $store->store_friends($client->friends); - $store->store_followers($client->followers); - 1; -} -catch ($e) { - print "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"; + 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"; + } + }; }; + -- cgit v1.2.3