our (%commodmap);
our ($pctb) = 'http://pctb.ilk.org/';
-our ($ua);
+our ($ua)= LWP::UserAgent->new;
sub load_commodmap() {
undef %commodmap;
}
sub refresh_commodmap() {
- my $ua= LWP::UserAgent->new;
my $resp= $ua->get("$pctb/commodmap.php?version=2");
die $resp->status_line unless $resp->is_success;
$current= $commod{$commod};
my $l= bs_p($commod,$bs,$sortmul);
next unless @$l;
-#print STDERR "COMMOD $commod @$l\n";
-
+#print STDERR "COMMOD $commod has ".scalar(@$l)."\n";
+ $o .= writeint($commodmap{$commod});
$o .= writeint(scalar @$l);
foreach my $cs (@$l) {
$stall= $cs->{Stall};
if (!defined $stallix) {
push @stallmap, $stall;
$stallmap{$stall}= $stallix= @stallmap;
+#print STDERR "STALL DEF $stallix $stall\n";
}
my $qty= $cs->{Qty};
$qty =~ s/^\>\s*//;
sub writeint { return pack 'v*', @_; }
-sub main__genmarketdata () {
+sub genmarketdata () {
our $version= '005b';
load_commodmap();
if $missing;
}
- my $o='';
- $o .= bs_gen_md(Buy, -1);
- $o .= bs_gen_md(Sell,+1);
-
- printf("$version\n".
- "%d\n",
- scalar(@stallmap))
- or die $!;
- foreach $stall (@stallmap) { print "$stall\n" or die $!; }
+ my $ob='';
+ $ob .= bs_gen_md(Buy, -1);
+ $ob .= bs_gen_md(Sell,+1);
- print $o or die$!;
+ my $ot= sprintf("$version\n".
+ "%d\n",
+ scalar(@stallmap));
+ foreach $stall (@stallmap) { $ot .= "$stall\n"; }
+ return $ot.$ob;
}
+sub main__genmarketdata () {
+ my $o= genmarketdata();
+ print $o or die $!;
+}
sub main__upload () {
- die "\nUploading not yet implemented, sorry.\n";
+ my $o= genmarketdata();
+ my $url= "$pctb/upload.php";
+ $url= "http://www.chiark.greenend.org.uk/ucgi/~ijackson/check/upload.php";
+ my $content= {
+ 'marketdata' => [ undef, "marketdata.gz",
+ Content_Type => 'application/gzip',
+ Content => $o
+ ]
+ };
+ my $resp= $ua->post("$url", Content => $content,
+ Content_Type => 'form-data');
+ die $resp->status_line unless $resp->is_success;
+
+ print "[[ ",$resp->content," ]]\n";
}