From 92e646ff78152142bc63c4789c4051121c142950 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 13 Sep 2011 23:20:38 -0500 Subject: initial implementation --- bin/update_twitter | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 bin/update_twitter (limited to 'bin/update_twitter') diff --git a/bin/update_twitter b/bin/update_twitter new file mode 100644 index 0000000..c5eb888 --- /dev/null +++ b/bin/update_twitter @@ -0,0 +1,46 @@ +#!/usr/bin/env perl +use strict; +use warnings; +# PODNAME: update_twitter + +use JSON; +use Linkulator::Twitter; +use Path::Class; +use Try::Tiny; + +my $state_file = 'state.json'; +if (!-e $state_file) { + file($state_file)->openw->print(encode_json({last_tweeted => 0})); +} + +my $conf = decode_json(file($state_file)->slurp); + +my $lt = Linkulator::Twitter->new( + exists $conf->{token} && exists $conf->{token_secret} + ? (twitter_access_token => $conf->{token}, + twitter_access_token_secret => $conf->{token_secret}) + : (), +); + +if (my $url = $lt->authenticate_twitter) { + print "Authorize this app at $url and enter the pin here: "; + + my $pin = ; + chomp $pin; + + my ($token, $secret) = $lt->authenticate_twitter($pin); + $conf->{token} = $token; + $conf->{token_secret} = $secret; +} + +try { + $lt->update; + for my $link (sort { $a->id <=> $b->id } $lt->links) { + next if $link->id <= $conf->{last_tweeted}; + $lt->tweet($link); + $conf->{last_tweeted} = $link->id; + } +} +finally { + file($state_file)->openw->print(encode_json($conf)); +}; -- cgit v1.2.3-54-g00ecf