X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fcommod-results-processor;h=37484d6ef6ff071172036578b55a1eef3d2bb301;hp=e53bbb58c1351283043d6371abfc4bc0589fe9d5;hb=da7ce28baf19eb34178ee4886216ee3fb2c89321;hpb=1c640671a7ee8d30ee80c393822fa02ef3da0031 diff --git a/yarrg/commod-results-processor b/yarrg/commod-results-processor index e53bbb5..37484d6 100755 --- a/yarrg/commod-results-processor +++ b/yarrg/commod-results-processor @@ -29,7 +29,6 @@ use strict (qw(vars)); use HTTP::Request; use IO::File; use POSIX; -use LWP::UserAgent; use XML::Parser; use Commods; @@ -52,6 +51,7 @@ sub bs_read ($$) { return if @v <= $c; my ($price,$qty) = @v[$c..$c+1]; return if !length($price) && !length($qty); + die "$price ?" unless $price =~ m/^\d/; die "$_ ?" unless length($price) && length($qty); $commod{$commod}{$bs}{$stall}= { Stall => $stall, @@ -64,6 +64,10 @@ while (<>) { chomp; @v= split /\t/; #print STDERR "[".join("|",@v)."]\n"; + foreach (@v[2..$#v]) { + s/\,//g; + die "$_ ?" if m/.\D/; + } ($commod,$stall) = @v; bs_read(Buy, 2); bs_read(Sell, 4); @@ -129,16 +133,18 @@ sub main__arbitrage () { $info.= sprintf("%-13.13s| %-19.19s %4d| %-19.19s %4d|%3d x%3d =%3d\n", $commod, - $buys[0]{Stall},$buys[0]{Price}, $sells[0]{Stall},$sells[0]{Price}, + $buys[0]{Stall},$buys[0]{Price}, $qty, $pricediff, $tprofit); sub arb_subtract_qty (\@) { my ($verbs) = @_; my $verb= shift @$verbs; + my $vqty= $verb->{Qty}; + $vqty =~ s/^\>//; unshift @$verbs, { Stall => $verb->{Stall}, Price => $verb->{Price}, - Qty => $verb->{Qty} - $qty + Qty => $vqty - $qty }; } arb_subtract_qty(@buys); @@ -203,8 +209,8 @@ sub bs_p_tsv ($$) { } } -sub write_tsv ($) { - my ($f) = @_; +sub write_tsv ($$) { + my ($f,$showhold) = @_; foreach $commod (sort keys %commod) { $current= $commod{$commod}; my %stalls; @@ -214,6 +220,9 @@ sub write_tsv ($) { printf($f "%s\t%s", $commod, $stall) or die $!; bs_p_tsv($f, Buy); bs_p_tsv($f, Sell); + if ($showhold && $commod{$commod}{Hold}) { + printf($f "\t%s", $commod{$commod}{Hold}) or die $!; + } print($f "\n") or die $!; } } @@ -222,13 +231,13 @@ sub write_tsv ($) { } sub main__tsv () { - write_tsv(\*STDOUT); + write_tsv(\*STDOUT,1); } our ($pctb) = $ENV{'YPPSC_YARRG_PCTB'}; -our ($ua)= LWP::UserAgent->new; +our ($ua)= http_useragent("commod-results-processor $mode"); sub refresh_commodmap() { die unless $pctb; @@ -286,7 +295,16 @@ sub refresh_commodmap() { my $content= $resp->content; # print STDERR "[[[$content]]]\n"; - $xp->parse($content); + my $commodmapxmltmp= '_commodmap.xml'; + if (!eval { + $xp->parse($content); 1; + }) { + open R, ">./$commodmapxmltmp" or die $!; + print R $content or die $!; + close R or die $!; + die "$@ parsing commodmap"; + } + unlink $commodmapxmltmp or $!==&ENOENT or die $!; close $o or die $!; rename "_commodmap.tsv.tmp","_commodmap.tsv" or die $!; } @@ -439,7 +457,7 @@ sub main__uploadyarrg () { $o{'timestamp'}= $ENV{'YPPSC_DATA_TIMESTAMP'} or die; my $tf= pipethrough_prep(); - write_tsv($tf); + write_tsv($tf,0); my $oz= pipethrough_run_gzip($tf); $o{'data'}= [ undef, 'deduped.tsv.gz', Content_Type => 'application/octet-stream', @@ -447,6 +465,8 @@ sub main__uploadyarrg () { my $respcontent= yarrgpostform($ua, \%o); $respcontent =~ m/^OK\b/ or die "$respcontent ?"; + $respcontent =~ s/^/ /mg; + print $respcontent,"\n"; } sub main__uploadpctb () {