dotfiles/bin/hn2bookmarks.pl

61 lines
1.2 KiB
Perl
Raw Permalink Normal View History

2011-04-24 10:36:19 +00:00
#!/usr/bin/perl
#
#
# This perl script is dumping the urls submitted
# by an HN user. Sometime it's better than any
# del.icio.us stream when the HN user has some
# special interests.
#
# Usage:
#
# perl hn2bookmarks.pl <hnusername>
#
# by Alexandre Dulaunoy, released under the modified BSD license.
#
2011-04-24 10:36:19 +00:00
use Scrappy;
my $spidy = Scrappy->new;
my $username = $ARGV[0];
my $url = "http://news.ycombinator.com/submitted?id=" . $username;
2011-04-24 10:36:19 +00:00
my @bookmarks;
sub hnfetch {
my $url = shift;
2011-04-24 10:36:19 +00:00
print STDERR "Fetching " . $url . "\n";
$spidy->crawl(
$url,
{
'table td a' => sub {
if ( $_[0]->{href} =~ m/^http/ ) {
push( @bookmarks, $_[0]->{href} )
if not( $_[0]->{href} =~ m/^http:\/\/ycombinator.com/ );
}
2011-04-24 10:36:19 +00:00
if ( $_[0]->{text} =~ m/^More$/ ) {
my $nextpage =
"http://news.ycombinator.com" . $_[0]->{href};
hnfetch($nextpage);
last;
}
2011-04-24 10:36:19 +00:00
},
2011-04-24 10:36:19 +00:00
}
)
2011-04-24 10:36:19 +00:00
}
hnfetch($url);
# remove footer URLs
splice( @bookmarks, -3 );
foreach (@bookmarks) {
print $_. "\n";
}