#!/usr/bin/env perl
use 5.024;
use strict;
use warnings;
use Path::Class;
use JSON::MaybeXS;
use Dakkar::TweetArchive;
use Dakkar::TweetArchive::Store;

my $json_parser = JSON::MaybeXS->new(
    utf8 => 1,
    relaxed => 1,
);

my $conf = $json_parser->decode(
    file(__FILE__)->parent->file('tweet-archive.conf')
        ->slurp(iomode=>'<:raw')
            // '{}'
    );

my $client = Dakkar::TweetArchive->new($conf);
my $store = Dakkar::TweetArchive::Store->new($conf);

my $latest_id = $store->latest_tweet_id;

for my $tweet ($client->home_timeline($latest_id)->@*) {
    $store->store_tweet($tweet);
}

$store->store_friends($client->friends);
$store->store_followers($client->followers);
