7

The following quickie command line application formats a list of questions obtained from search results.

Requirements:

Perl, JSON

Usage:

  1. Retrieve a list of questions from the API (from the /questions/{ids} or /search route, maybe others) into one or more JSON file.
  2. Call the script on the JSON file(s).
  3. Copy-paste the output into a post on meta.*.

Example:

wget -O list+recommendations-1.json 'http://api.scifi.stackexchange.com/1.1/search?tagged=list;recommendations'
wget -O list+recommendations-2.json 'http://api.scifi.stackexchange.com/1.1/search?tagged=list;recommendations&page=2'
wget -O list+recommendations-3.json 'http://api.scifi.stackexchange.com/1.1/search?tagged=list;recommendations&page=3'
show_questions https://scifi.stackexchange.com/ list+recommendations-?.json

Result: this meta.scifi question, e.g.

The script:

#! /usr/bin/env perl

## Usage: $0 http://stackoverflow.com/ questions.json ...

use strict;
use warnings;
use File::Slurp qw(slurp);
use JSON;

my $root = $ARGV[0]; shift; $root =~ s!/$!!;

my @questions =
  sort {$a->{question_id} <=> $b->{question_id}}
  map {@{$_->{questions}}}
  map {from_json(slurp($_))} @ARGV;

foreach my $q (@questions) {
    my $title = $q->{title}; $title =~ s/([*<>\[\]\`\\])/\\$1/g;
    my $url = "$root/questions/" . $q->{question_id};
    my $answers = $q->{answer_count};
    print "* [$title]($url) ($answers)\n";
}
1
  • +1 - I sure could have used this script here. Commented Feb 28, 2011 at 20:10

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.