Skip to content

Instantly share code, notes, and snippets.

@wata
Created January 2, 2012 16:27
Show Gist options
  • Save wata/1551301 to your computer and use it in GitHub Desktop.
Save wata/1551301 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use 5.010;
use utf8;
use Time::Piece;
use Furl;
use JSON;
use Term::ReadKey qw/GetTerminalSize/;
my $id = '101763292'; # zeebratv
my $ua = Furl->new;
my $p = 0;
&main while 1;
# -------------------------------------------------------------------------
sub width { (GetTerminalSize)[0] }
sub main {
$p++;
my $u = 'http://api.twitter.com/1/statuses/user_timeline.json?page=' . $p . '&user_id=' . $id;
my $content = do {
my $res = $ua->get($u);
die $res->status_line unless $res->is_success;
$res->content;
};
foreach my $tweet (@{ decode_json($content) }) {
if ($tweet->{text} =~ /♬WZBR Now Playing: ([^by]+) by (.+)/) {
my $title = $1;
my $artist = $2;
my $date = localtime->strptime($tweet->{created_at}, '%a %b %d %H:%M:%S +0000 %Y') + 32400;
say "-" x width;
say "title : " . $title;
say "artist: " . $artist;
say "date : " . join ' ', $date->time, $date->date;
}
}
<STDIN>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment