chiark / gitweb /
Recompress the tsv (and err make it work again??)
[ypp-sc-tools.web-live.git] / pctb / commod-update-receiver
index 1fe86125f93ffdd1fe2014f0d010e0d6f701d671..2c02c11bcb74603ada8f65b062988699d66ec00a 100755 (executable)
@@ -127,7 +127,7 @@ sub ksmap ($) {
 
 foreach my $vn (sort { ksmap($a) cmp ksmap($b) } keys %o) {
     my $val= $o{$vn};
-    die if $val =~ m/\n|\r|\t/;
+    die if $val =~ m/\n|\r/;
     $metadata .= "$vn\t$o{$vn}\n";
 }
 
@@ -146,35 +146,24 @@ if (!$gunzchild) {
     exec 'gunzip'; die $!;
 }
 
-sub bad_data ($) { fail("bad data: line $.: $_[0]"); }
-
-our %done;
+my $dedupedtsv= pipethrough_prep();
 
 while (<GZ>) {
-    !m/\P{IsPrint}/ or die bad_data('nonprinting char(s)');
-    !m/\\/ or bad_data('data contains backslashes');
-    my @v= split /\t/;
-    @v==6 or bad_data('wrong number of fields');
-    my ($commod,$stall) = @v;
-    defined $commods{$commod} or bad_data("unknown commodity \`$commod'");
-    $stall =~ m/^\p{IsUpper}|^[0-9]/ or bad_data("stall not capitalised");
-    !exists $done{$commod,$stall} or bad_data("repeated data");
-    $done{$commod,$stall}= 1;
-    foreach my $i (2..5) {
-       my $f= $v[$i];
-       $f =~ m/^(|0|[1-9][0-9]{0,5}|\>1000)$/ or bad_data("bad field $i");
-       ($i % 2) or ($f !~ m/\>/) or bad_data("> in field $i price");
-    }
+    my @v= check_tsv_line($_,\&fail);
+    print $dedupedtsv join('\t',@v),"\n" or die $!;
 }
+
 GZ->error and die $!;
 $?=0; close GZ; $? and fail("gunzip for check failed code $?");
 
+my $launderedgz= pipethrough_run($dedupedtsv,undef,'gzip','gzip');
+
 my $mdatafile= MIME::Entity->build(Top => 0,
                                   Type => 'application/octet-stream',
                                   Disposition => 'attachment',
                                   Encoding => 'base64',
                                   Filename => 'deduped.tsv.gz',
-                                  Path => $datafile);
+                                  Data => $launderedgz);
 $mcontent->add_part($mdatafile);
 
 open M, "|/usr/sbin/sendmail -t -oi -oee -odb"