send toots

This commit is contained in:
Anonymous 2017-05-10 16:36:30 +01:00
parent f4eb471d79
commit a1f17e3922
3 changed files with 38 additions and 1 deletions

View File

@ -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 => [],
},
}
);

View File

@ -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";

33
lobstertoot.pl Normal file
View File

@ -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);
}