#!perl use strict; use vars qw($opt_usage @opt_ref $opt_debug $queries $lastref); use XML::Twig; use LWP::Simple; #MAIN { process_options(); foreach my $ref (@opt_ref) { my $text = query_passage($ref); my $esvlink = "($ref)"; my $esv=XML::Twig->new(twig_handlers => { p => sub { $_->set_gi('span'); }, 'div[@class="esv"]' => sub { $_->set_gi('blockquote'); $_->prefix("\""); $_->suffix("\" $esvlink"); }, 'div[@class="esv-text"]' => sub { $_->set_gi('span'); }, br => sub { $_->delete; } }, keep_encoding => 1); $esv->setEndTagHandler("div", sub { print "trailer"; }); $esv->parse($text); $esv->flush; # flush the end of the document print "\n"; } } sub query_passage { my ($passage) = @_; my $key = "TEST"; my $options = "action=doPassageQuery&include-verse-numbers=false&include-passage-references=false&include-footnotes=false&include-headings=false&include-subheadings=false&include-short-copyright=false"; $queries++; return get("http://www.gnpcb.org/esv/share/get/?key=$key&passage=$passage&$options"); } sub process_options { $opt_usage = 0; $opt_debug = 0; @opt_ref = (); # Parse the command line options use Getopt::Long; &GetOptions("usage|help|?", "ref=s" => \@opt_ref, # unadvertised "debug"); if ($opt_usage) {print usage(); exit 0;} unless (@opt_ref) { die "Need a reference\n".usage(); } @opt_ref = split(',', join(',', @opt_ref)); } sub usage { return "usage: $ARGV[0] -ref col.3.16 Read an input file in 'index' format, connect to the ESV web service to download the verse content for each item, merge in additional index file content and write to stdout. "; }