From 1dca157e297babaf8a54a7710c45e8bd78ec6c42 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sun, 24 Apr 2011 17:28:52 +0200 Subject: [PATCH] hn2bookmarks add username as an argument --- bin/hn2bookmarks.pl | 58 ++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/bin/hn2bookmarks.pl b/bin/hn2bookmarks.pl index 6967e51..7ca41d2 100644 --- a/bin/hn2bookmarks.pl +++ b/bin/hn2bookmarks.pl @@ -1,40 +1,60 @@ #!/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 +# +# by Alexandre Dulaunoy, released under the modified BSD license. +# use Scrappy; 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; sub hnfetch { - my $url = shift; + my $url = shift; - print STDERR "Fetching ".$url."\n"; -$spidy->crawl( $url, -{ - 'table td a'=> sub { - if ($_[0]->{href} =~ m/^http/) { - push (@bookmarks, $_[0]->{href}); - } + 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/ ); + } - if ($_[0]->{text} =~ m/^More$/) { - my $nextpage = "http://news.ycombinator.com".$_[0]->{href}; - hnfetch($nextpage); - last; - } + if ( $_[0]->{text} =~ m/^More$/ ) { + my $nextpage = + "http://news.ycombinator.com" . $_[0]->{href}; + hnfetch($nextpage); + last; + } - }, + }, -} -) + } + ) } hnfetch($url); -print @bookmarks; +# remove footer URLs +splice( @bookmarks, -3 ); + +foreach (@bookmarks) { + print $_. "\n"; +}