Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

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 http://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";
}
share|improve this question
    
+1 - I sure could have used this script here. –  Nathan Osman Feb 28 '11 at 20:10
add comment

You must log in to answer this question.

Browse other questions tagged .