hn2bookmarks add username as an argument

This commit is contained in:
Alexandre Dulaunoy 2011-04-24 17:28:52 +02:00
parent 320014e157
commit 1dca157e29

View file

@ -1,12 +1,24 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# http://news.ycombinator.com/submitted?id=adulau #
# 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.
#
use Scrappy; use Scrappy;
my $spidy = Scrappy->new; my $spidy = Scrappy->new;
my $url = "http://news.ycombinator.com/submitted?id=adulau"; my $username = $ARGV[0];
my $url = "http://news.ycombinator.com/submitted?id=" . $username;
my @bookmarks; my @bookmarks;
@ -15,15 +27,18 @@ sub hnfetch {
my $url = shift; my $url = shift;
print STDERR "Fetching " . $url . "\n"; print STDERR "Fetching " . $url . "\n";
$spidy->crawl( $url, $spidy->crawl(
$url,
{ {
'table td a' => sub { 'table td a' => sub {
if ( $_[0]->{href} =~ m/^http/ ) { if ( $_[0]->{href} =~ m/^http/ ) {
push (@bookmarks, $_[0]->{href}); push( @bookmarks, $_[0]->{href} )
if not( $_[0]->{href} =~ m/^http:\/\/ycombinator.com/ );
} }
if ( $_[0]->{text} =~ m/^More$/ ) { if ( $_[0]->{text} =~ m/^More$/ ) {
my $nextpage = "http://news.ycombinator.com".$_[0]->{href}; my $nextpage =
"http://news.ycombinator.com" . $_[0]->{href};
hnfetch($nextpage); hnfetch($nextpage);
last; last;
} }
@ -37,4 +52,9 @@ $spidy->crawl( $url,
hnfetch($url); hnfetch($url);
print @bookmarks; # remove footer URLs
splice( @bookmarks, -3 );
foreach (@bookmarks) {
print $_. "\n";
}