#!/usr/bin/env perl

# Scrape a "thread unrolling" generated by https://threadreaderapp.com/,
# generating a JSON array of tweet contents in output.
#
# E.g. try https://threadreaderapp.com/thread/1215710451343904768.html

use strict;
use warnings;
use feature 'say';
use Mojo::DOM;
use Mojo::File;
use Mojo::UserAgent;
use Mojo::JSON 'j';
my $ua    = Mojo::UserAgent->new;
my $input = shift @ARGV;
my $dom =
    $input =~ m{\A https?:// }imxs
  ? $ua->get($input)->result->dom
  : Mojo::DOM->new(Mojo::File->new($input)->slurp);
my @tweets;
$dom->find('div[id^=tweet_]')->each(sub { push @tweets, $_[0]->content });
say j \@tweets;
