From 2217bf2831c2af1d2607672693d463c5c60da6f3 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 5 Sep 2009 12:01:07 +0200 Subject: [PATCH 1/1] Initial commit. identica.pl is a *very* simple command line Identi.ca client. It currently supports the following commands: * '?' print the user's timeline * '??' print the timeline of the user and her friends * everything else will be used as an update to the user's status The first two commands may be appended (without any whitespace) by a number, specifying the number of entries to be returned (default: 5). The script requires a simple config file in ~/.identica.conf specifying the connection parameters. That file has to include valid Perl code. --- identica.pl | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 identica.pl diff --git a/identica.pl b/identica.pl new file mode 100755 index 0000000..35a2c39 --- /dev/null +++ b/identica.pl @@ -0,0 +1,161 @@ +#! /usr/bin/perl +# +# Copyright © 2009 Sebastian "tokkee" Harl +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holders nor the names of their +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS +# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Author: +# Sebastian "tokkee" Harl + +use strict; +use warnings; + +use utf8; + +use Term::ANSIColor; + +use Net::Twitter::Lite; + +my $conf_file = "$ENV{'HOME'}/.identica.conf"; + +my ($fh, $nt); +my %id; + +# This file should fill the %id hash. +# +# See for details about which parameters +# are available. +if (! open($fh, '<', $conf_file)) { + print_err("Failed to open config file ($conf_file): $!\n"); + exit 1; +} + +{ + my @conf = <$fh>; + eval join '', @conf; +} + +close($fh); + +if (! $id{'identica'}) { + print_err('id{identica} has not been set - ' + . 'Twitter is not currently supported!' . "\n"); + exit 1; +} + +$nt = Net::Twitter::Lite->new(%id); + +if (! $nt) { + print_err("Failed to create Net::Twitter::Lite object: $!\n"); + exit 1; +} + +while (42) { + my $msg = ""; + my $status; + my $err; + + print "identi.ca> ", ' ' x 140, '←', "\r"; + print color 'bold'; + print "identi.ca> "; + print color 'reset'; + + $msg = ; + + if (! defined($msg)) { + last; + } + elsif ($msg =~ m/^\?(\?)?(\d+)?$/) { + my $friends = $1; + my $count = $2; + my $posts; + + if (! defined($count)) { + $count = 5; + } + + eval { + if (defined $friends) { + $posts = $nt->friends_timeline({count => $count}); + } + else { + $posts = $nt->user_timeline({count => $count}); + } + }; + + if ($err = $@) { + print_err("Failed to get ``tweeds'': $err\n"); + next; + } + + foreach my $post (@$posts) { + my $text = $post->{'text'}; + my $source = $post->{'source'}; + + utf8::upgrade($text); + + if ($source =~ m/^(.*)<\/a>$/) { + $source = $1; + } + + print $post->{'created_at'} . ' ('; + print color 'bold blue'; + print $post->{'user'}->{'screen_name'}; + print color 'reset'; + print ", $source): "; + print color 'dark yellow'; + print "$text\n"; + print color 'reset'; + } + next; + } + + eval { + $status = $nt->update({ status => $msg }); + }; + + if ($err = $@) { + print_err("Failed to send message: $err\n"); + next; + } + + print color 'bold green'; + print 'http://identi.ca/notice/' . $status->{'id'} . "\n"; + print color 'reset'; +} + +print color 'bold'; +print "\nBye!\n"; +print color 'reset'; + +sub print_err { + print STDERR color 'bold red'; + print STDERR join(' ', @_); + print STDERR color 'reset'; +} + +# vim: set noexpandtab tw=78 sw=4 ts=4 : + -- 2.30.2