From: Ian Jackson Date: Mon, 15 Jun 2009 00:34:04 +0000 (+0100) Subject: WIP island determination; pixoptions can list islands X-Git-Tag: 1.9.2~124^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=commitdiff_plain;h=3768c30b78a0afa7ca2c69c21365429c98cd868a WIP island determination; pixoptions can list islands --- diff --git a/pctb/yppsc-resolver-pixoptions b/pctb/yppsc-resolver-pixoptions index 260c5a2..eff5b02 100755 --- a/pctb/yppsc-resolver-pixoptions +++ b/pctb/yppsc-resolver-pixoptions @@ -24,12 +24,76 @@ # are used without permission. This program is not endorsed or # sponsored by Three Rings. +use strict (qw(vars)); +use LWP::UserAgent; +use JSON; +#use Data::Dumper; + @ARGV==1 or die "You probably don't want to run this program directly.\n"; our ($which) = shift @ARGV; $which =~ s/\W//g; -&{"main__$which"}(); +our ($pctb)= 'http://pctb.ilk.org/'; +our ($ua)= LWP::UserAgent->new; +our $jsonresp; + +sub jparsetable ($$) { + my ($jobj,$wh) = @_; + my $jtab= $jobj->{$wh}; + die "$jsonresp $wh ?" unless defined $jtab; + my $cns= $jtab->{'colNames'}; die "$jsonresp $wh ?" unless defined $cns; + my $ad= $jtab->{'arrayData'}; die "$jsonresp $wh ?" unless defined $ad; + my @o=(); + foreach my $ai (@$ad) { + @$ai == @$cns or die "$jsonresp $wh ".scalar(@o)."?"; + my $v= { }; + for (my $i=0; $i<@$cns; $i++) { + $v->{$cns->[$i]} = $ai->[$i]; + } + push @o, $v; + } + return @o; +} +sub sort_by_name { + sort { + $a->{'name'} cmp $b->{'name'}; + } @_; +} + +sub p ($) { print $_[0] or die $!; } +sub ptcl ($) { + local ($_) = @_; + die "$_ $& ?" if m/[^-+'"# 0-9a-z]/i; + p("{$_[0]}"); +} + +sub main__island () { + my $url= "$pctb/islands.php?oceanName=MIDNIGHT"; + my $resp= $ua->get($url); + die $resp->status_line unless $resp->is_success; + $jsonresp= $resp->content; + my $jobj= jsonToObj($resp->content); + my @arches= jparsetable($jobj, 'arches'); + my @islands= jparsetable($jobj, 'islands'); +# print Dumper(\@arches, \@islands); + my $islands_done=0; + foreach my $arch (sort_by_name(@arches)) { +# print Dumper($arch); + my $aname= $arch->{'name'}; + die "$jsonresp ?" unless defined $aname; + ptcl($aname); p(' '); ptcl($aname); p(" {\n"); + foreach my $island (sort_by_name(@islands)) { + my $iname= $island->{'name'}; + die "$jsonresp $aname ?" unless defined $iname; + next unless $arch->{'id'} == $island->{'arch'}; + p(' '); ptcl($iname); p(' '); ptcl($iname); p("\n"); + $islands_done++; + } + p("}\n"); + } + die "$jsonresp $islands_done ?" unless $islands_done == @islands; +} sub main__sunshinewidget () { print <