use URI;
use Web::Scraper;
my $tweets_url = "http://twitter.com/%s";
my $tweets_query = scraper {
process 'li[data-item-type="tweet"]', 'tweets[]' => scraper {
process '*[data-name]', 'name' => '@data-name';
process '*[data-time]', 'time' => '@data-time';
process '.content p', 'text' => 'TEXT';
};
};
my $tweets = $tweets_query->scrape(
URI->new(sprintf $tweets_url, $ARGV[0]));
for my $tweet (@{$tweets->{tweets}}[0..4]) {
last if !$tweet;
my $date = strftime('%b %d', localtime $tweet->{time});
print "\n$tweet->{name} tweeted on $date:\n $tweet->{text}\n";
}
####
use My::Query qw(register_query);
register_query 'recent_tweets' => {
url => "http://twitter.com/%s",
items => '//li[@data-item-type="tweet"]',
parse => { 'name' => '//@data-name',
'time' => '//@data-time',
'text' => '//*[@class="content"]/p' },
}
my $it = recent_tweets( $ARGV[0] );
for (0..4) {
my $tweet = $it->() or last;
my $date = strftime('%b %d', localtime $tweet->{time});
print "\n$tweet->{name} tweeted on $date:\n $tweet->{text}\n";
}
####
$ ./recent-tweets.pl TimToady
Larry Wall tweeted on Mar 15:
@anocelot Lemme guess, only the first word is different...
Larry Wall tweeted on Mar 13:
I need to ask the Guinness folks what the current world record is for number of invitations to connect on LinkedIn ignored.
Larry Wall tweeted on Feb 14:
@genespeth \o/
Larry Wall tweeted on Feb 12:
Let us not forget that the perfect is also the enemy of the bad and the ugly.
Larry Wall tweeted on Feb 03:
Wow. Just...wow. #sb48