When I signed in this morning Micha greets me with his status of eliminating the first pot of coffee. Very interesting… So we decided to start twittering ;)

This version is deprecated since twitter disabled Basic Authentication. For a new version see Twitter disabled Basic Authentication

I already registered an account about ten months ago, just to see how it works, but now I’ll try to show some activity and tweet a lot of boring things..

First of all I developed a little script that tweets my messaged via curl:

#!/bin/bash

user=USER
msg=$*
if [ "${#msg}" -gt 140 ]
then
    echo "msg too long: ${#msg}"
    exit 1
fi

curl --basic -u $user -d status="$msg" https://twitter.com/statuses/update.xml >> /dev/null

Just call it with your message, it will ask for a passphrase to your account.. Just download it and use it like ./tweet.sh yeah it works .

And of course I’ve written a script that dumps all news to my console. To parse the XML I’m using Perl:

#!/usr/bin/perl -w
use warnings;
use strict;
use LWP::UserAgent;
use XML::TreeBuilder;
use XML::Entities;
use POSIX;
binmode STDOUT, ":utf8";

my $max = 10;
$max = $ARGV[0] if ($ARGV[0] && isdigit ($ARGV[0]));

my $browser = LWP::UserAgent->new;
$browser->credentials('twitter.com:443', 'Twitter API', 'USER' => 'PASSWORD' );
my $response = $browser->get('https://twitter.com/statuses/friends_timeline.xml');
die "failed...\\n" . $response->status_line if (!$response->is_success);
my $tree = XML::TreeBuilder->new();
$tree->parse($response->decoded_content);

my $anz = 1;
foreach my $status ($tree->find_by_tag_name ('status'))
{
	my $time = XML::Entities::decode ('all', $status->find_by_tag_name ('created_at')->as_text);
	my $text = XML::Entities::decode ('all', $status->find_by_tag_name ('text')->as_text);
	my $user = XML::Entities::decode ('all', $status->find_by_tag_name ('user')->find_by_tag_name ('screen_name')->as_text);
	print "$text\\n\\tby $user at $time\\n\\n";
	last if (++$anz > $max);
}

A little bit more code, but easy to use! Just download and run it with ./twitstat.pl [MAX_NUMBER_OF_TWEETS] . (You may need some additional Perl libs)

So let’s see how long I keep going on.. You can follow me at http://twitter.com/binfalse

Downloads: Bash: tweet.sh (tweet from command line) Perl: twitstat.pl (get latest news) (Please take a look at the man-page. Browse bugs and feature requests.)

Martin Scharm

stuff. just for the records.

Do you like this page?
You can actively support me!

1 comment

binfalse | Permalink |

Twitter disabled Basic Authentication…

Some of you may have recognized that twitter has disabled the so called Basic Authentication. So my previous twitter-tools don’t work anymore. But don’t bury your head in the sand, here are the newer versions…….

Leave a comment

There are multiple options to leave a comment: