diff --git a/auth.pl b/auth.pl index f2adf60..aa9ac7d 100644 --- a/auth.pl +++ b/auth.pl @@ -29,12 +29,14 @@ $masto->authorize( say encode_json( { masto => { + instance => $inst, client_id => $masto->client_id, client_secret => $masto->client_secret, access_token => $masto->access_token, }, lobsters => { url => "https://lobste.rs", + storiesdone => [], }, } ); diff --git a/cpanfile b/cpanfile index 7934647..1685ea3 100644 --- a/cpanfile +++ b/cpanfile @@ -1,4 +1,6 @@ -requires "Mastodon::Client" => "0"; +requires "Mastodon::Client" => "0.011"; # 0.010 is buggy +requires "LWP::UserAgent" => "0"; requires "IO::Prompt" => "0"; requires "LWP::Protocol::https" => "0"; requires "JSON::Tiny" => "0"; +requires "File::Slurp" => "0"; diff --git a/lobstertoot.pl b/lobstertoot.pl new file mode 100644 index 0000000..af5c98f --- /dev/null +++ b/lobstertoot.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +use 5.010; +use strict; +use warnings; +use Mastodon::Client; +use JSON::Tiny qw/encode_json decode_json/; +use File::Slurp; +use LWP::UserAgent; + +my $s = decode_json read_file("state.json"); + +my $ua = new LWP::UserAgent; +$ua->agent("lobstertoot (".$ua->_agent.") - for info contact albino\@autistici.org"); +my $resp = $ua->get("$s->{lobsters}->{url}/hottest.json"); +die unless $resp->is_success; +my $stories = decode_json $resp->decoded_content; + +my $masto = new Mastodon::Client ( + name => "lobstertoot", + coerce_entities => 1, + %{ $s->{masto} }, +); + +for my $story (@{$stories}) { + next if grep {$_ eq $story->{short_id}} @{ $s->{lobsters}->{storiesdone} }; + + my $toot = "$story->{title} $story->{url} | $s->{lobsters}->{url}/s/$story->{short_id}"; + for (@{ $story->{tags} }) { + $toot .= " #$_"; + } + + $masto->post_status($toot); +}