X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Fcommod-results-processor;h=cea64e5190318e437c5ad55ff6368cfe0f8a68ed;hb=05700033bb05f67407798385699519a96da803c0;hp=c3cbe8e1b479447245540556754789863109f453;hpb=9068e6f370b8a2913ffb3eafbe69fcf0d29e3d51;p=ypp-sc-tools.db-test.git diff --git a/pctb/commod-results-processor b/pctb/commod-results-processor index c3cbe8e..cea64e5 100755 --- a/pctb/commod-results-processor +++ b/pctb/commod-results-processor @@ -295,6 +295,39 @@ sub refresh_commodmap() { rename "#commodmap#.tsv.new","#commodmap#.tsv" or die $!; } +our %newcommods; + +sub read_newcommods ($) { + my ($file) = @_; + if (!open NC, "< $file") { + $!==&ENOENT or die $!; + return; + } + while () { + chomp; s/^\s*//; s/\s+$//; + next if m/^\#/; + next unless m/\S/; + $newcommods{$_}= 1; + } + NC->error and die $!; + close NC or die $!; +} + +sub refresh_newcommods() { + my $rsync= $ENV{'YPPSC_PCTB_RSYNC'}; + $rsync= 'rsync' if !defined $rsync; + + my $local= "#master-newcommods#.txt"; + my $src= $ENV{'YPPSC_PCTB_DICT_UPDATE'}; + if ($src) { + my $remote= "$src/master-newcommods.txt"; + $!=0; system 'rsync','-Lt','--',$remote,$local; + die "$? $!" if $! or $?; + } + read_newcommods($local); + read_newcommods('#local-newcommods#.txt'); +} + our (%stallmap, @stallmap); sub bs_gen_md ($$) { @@ -302,9 +335,11 @@ sub bs_gen_md ($$) { my $count= 0; my $o= ''; - foreach $commod (sort { - $commodmap{$a} <=> $commodmap{$b} - } keys %commod) { + foreach $commod ( + sort { $commodmap{$a} <=> $commodmap{$b} } + grep { exists $commodmap{$_} } + keys %commod + ) { #print STDERR "COMMOD $commod\n"; $current= $commod{$commod}; my $l= bs_p($commod,$bs,$sortmul); @@ -350,13 +385,19 @@ sub genmarketdata () { my @missing= grep { !exists $commodmap{$_} } keys %commod; if (@missing) { refresh_commodmap(); + refresh_newcommods(); my $missing=0; foreach $commod (sort keys %commod) { next if exists $commodmap{$commod}; - printf STDERR "Unknown commodity \`%s'!\n", $commod; - $missing++; + if (exists $newcommods{$commod}) { + printf STDERR "Ignoring new commodity \`%s'!\n", $commod; + } else { + printf STDERR "Unknown commodity \`%s'!\n", $commod; + $missing++; + } } - die "$missing unknown commoditi(es). OCR failure?\n" + die "$missing unknown commoditi(es).". + " See README (search for \`newcommods').\n" if $missing; } @@ -450,29 +491,32 @@ sub main__upload () { die "@forcerls ?" if grep { $_ ne $forcerl } @forcerls; my $setisland= { - 'action' => 'setisland', - 'filename' => $filename, - 'forcereload' => $forcerl, - 'ocean' => $oceanids[0], - 'island' => $islandid, }; print STDERR "Setting ocean and island...\n"; - $resp= $ua->post("${url}IWJTEST", $setisland); + my $siurl= ($url . "?action=setisland". + "&filename=$filename". + "&forcereload=$forcerl". + "&ocean=$oceanids[0]". + "&island=$islandid"); + $resp= $ua->get($siurl); + die $resp->status_line unless $resp->is_success; $resptxt= $resp->content(); save_upload_html('2', $resptxt); - - -# -#http://pctb.ilk.org/upload.php?&ocean=2&island=48&action=setisland&forcereload=1244748679&filename=PFayDW' >v.html -# -# print ">$filename|$forcerl|@oceanids|$islandid<\n"; + die unless $resptxt =~ m/your uploaded data has been processed/i; + die unless $resptxt =~ m/your data has been integrated into the database/i; - system 'printenv|grep YPP|sort'; + $resptxt =~ s/\[^<>]+\<\/a\>//g; + save_upload_html('3', $resptxt); + + print "\n" or die $!; + system('w3m -T text/html -dump < \#upload-3#.html'); + + print "\n" or die $!; }