X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=pctb%2Fcommod-results-processor;fp=pctb%2Fcommod-results-processor;h=0286ab3fd99a2203584dac2bc665f48748d37a1f;hp=cba01d9ac732a3713a3f658bf1910a456330f4dd;hb=b958771fa67513ba09630953ec91b9d21b3f42f9;hpb=769239e4cc9af0b88578d1b15a1b14a7cb3dc7ba diff --git a/pctb/commod-results-processor b/pctb/commod-results-processor index cba01d9..0286ab3 100755 --- a/pctb/commod-results-processor +++ b/pctb/commod-results-processor @@ -193,29 +193,36 @@ sub main__bestprices () { } } -sub bs_p_tsv ($) { - my ($bs) = @_; +sub bs_p_tsv ($$) { + my ($f, $bs) = @_; if (exists $current->{$bs}{$stall}) { my $si= $current->{$bs}{$stall}; - printf("\t%d\t%s", $si->{Price}, $si->{Qty}) or die $!; + printf($f "\t%d\t%s", $si->{Price}, $si->{Qty}) or die $!; } else { - printf("\t\t") or die $!; + printf($f "\t\t") or die $!; } } -sub main__tsv () { +sub write_tsv ($) { + my ($f) = @_; foreach $commod (sort keys %commod) { $current= $commod{$commod}; my %stalls; map { $stalls{$_}=1; } keys %{ $current->{Buy} }; map { $stalls{$_}=1; } keys %{ $current->{Sell} }; foreach $stall (sort keys %stalls) { - printf("%s\t%s", $commod, $stall) or die $!; - bs_p_tsv(Buy); - bs_p_tsv(Sell); - print("\n") or die $!; + printf($f "%s\t%s", $commod, $stall) or die $!; + bs_p_tsv($f, Buy); + bs_p_tsv($f, Sell); + print($f "\n") or die $!; } } + $f->error and die $!; + $f->flush or die $!; +} + +sub main__tsv () { + write_tsv(\*STDOUT); } @@ -426,30 +433,30 @@ sub save_upload_html ($$) { sub gzip ($) { my ($raw) = @_; - my $tf= IO::File::new_tmpfile() or die $!; + my $tf= pipethrough_prep(); print $tf $raw or die $!; - $tf->flush or die $!; - $tf->seek(0,0) or die $!; - my $child= open GZ, "-|"; defined $child or die $!; - if (!$child) { - open STDIN, "<&", $tf; - exec 'gzip'; die $!; - } - my $r; - { undef $/; $!=0; $r= ; } - defined $r or die $!; - close GZ or die "$! $?"; die $? if $?; - return $r; + return pipethrough_run($tf,undef,'gzip','gzip'); } sub main__uploadyaarg () { - my $ocean= $ENV{'YPPSC_OCEAN'}; die unless $ocean; - my $island= $ENV{'YPPSC_ISLAND'}; die unless $island; - my $content= { - 'data' => [ undef, 'deduped.tsv.gz', + my %o; + $o{'ocean'}= $ENV{'YPPSC_OCEAN'} or die; + $o{'island'}= $ENV{'YPPSC_ISLAND'} or die; + $o{'timestamp'}= 10; + get_our_version(\%o, 'client'); + + my $tf= pipethrough_prep(); + write_tsv($tf); + my $oz= pipethrough_run_gzip($tf); + $o{'data'}= [ undef, 'deduped.tsv.gz', Content_Type => 'application/octet-stream', - Content => '' -]}; + Content => $oz ]; + + my $dest= $ENV{'YPPSC_YAARG_SUBMIT'}; + + my $respcontent= cgipostform($ua, "$dest/commod-update-receiver", \%o); + + print $respcontent(); } sub main__uploadpctb () {