* hacker news on gopher
       
   URI git clone git://git.codevoid.de/hn-gopher
   DIR Log
   DIR Files
   DIR Refs
       ---
   DIR commit 1e75ee197e2cc218e808740151f74f1d3516cc87
   DIR parent 2b7e9e0f8bb755628f7f9e77174c93b95e299da6
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Mon, 30 Jul 2018 11:07:42 +0200
       
       Stop hierarchy from going wild
       
       - handle hierarchy > level 20
       - decrease hierarchy in recursion
       
       Diffstat:
         M hn-scraper.pl                       |      19 +++++++++++++------
       
       1 file changed, 13 insertions(+), 6 deletions(-)
       ---
   DIR diff --git a/hn-scraper.pl b/hn-scraper.pl
       @@ -53,6 +53,7 @@ sub scrapeSubComments {
                        $output .= formatContent("$author:", $lvl);
                        $output .= formatContent("$text", $lvl)."\n\n";
                        $output .= scrapeSubComments( $payload, $objectID, ++$lvl );
       +                $lvl--;
                    }
                }
            }
       @@ -80,9 +81,14 @@ sub formatContent {
            # remove trailing space before wrapping
            $content =~ s/ $/\n/g;
        
       +    my $pad="";
       +    if($lvl > 20) {
       +        $pad = "$lvl> ";
       +        $lvl = 19;
       +    }
       +
            # calculate padding
            $Text::Wrap::columns=72-($lvl*2);
       -    my $pad="";
            while($lvl > 0) {
              $pad="  ".$pad;
              $lvl--;
       @@ -186,31 +192,32 @@ sub saveFile {
        ### MAIN PROGRAM
        
        my ($selected_story) = @ARGV;
       -my $json_fp = getApiData("$api_uri/search_by_date?tags=front_page&numericFilters=points>60");
       +my $json_fp = getApiData("$api_uri/search_by_date?tags=front_page&numericFilters=points>20,num_comments>5&hitsPerPage=100");
        #my $json_fp = getApiData("$api_uri/search?tags=story");
        
        my $content = "";
        for my $hit ($json_fp->{"hits"}) {
            foreach my $story (@$hit) {
                my $title  = encode("UTF-8", $story->{'title'});
       +        $title =~ s/\|/\\|/g;
                my $url = "";
                if($story->{'url'}) {
                    $url    = encode("UTF-8", $story->{'url'});
       +            $content .= "[h|  $title|URL:$url|server|port]\n";
                } else {
       -            $url    = "/hn/story_$story->{'objectID'}.gph";
       +            $url    = "$go_path/story_$story->{'objectID'}.gph";
       +            $content .= "[1|  $title|$url|server|port]\n";
                }
                my $author = encode("UTF-8", $story->{'author'});
        
       -        $title =~ s/\|/\\|/g;
                $story->{'created_at'} =~ /(....-..-..)T(..:..).*/;
                my $date = $1;
                my $time = $2;
       -        my $number = 0;
       +        my $number = 0;
                if($story->{'num_comments'}) {
                    $number = $story->{'num_comments'};
                }
        
       -        $content .= "[h|  $title|URL:$url|server|port]\n";
                $content .= "  by $author ($story->{'points'} points) at $time ($date)\n";
                $content .= "[1|  read $number comments|$go_path/story_$story->{'objectID'}.gph|server|port]\n";
                $content .= "\n";