]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Scans.pm
Make Planet Scan parsing testable
[ndwebbie.git] / lib / NDWeb / Scans.pm
index bb05e99408d6bbe1cb69aea55b30a29f220f4df4..cfec2fd5ce4e7eb44441d3f77427a2d223619ffa 100644 (file)
@@ -24,7 +24,7 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/parseMilScan doMilScan/;
+our @EXPORT = qw/parseMilScan doMilScan doPlanetScan/;
 
 my %classes = (Fighter => 'Fi', Corvette => 'Co', Frigate => 'Fr', Destroyer => 'De', Cruiser => 'Cr', Battleship => 'Bs', Structure => 'St', Roids => 'Ro', Resources => 'Re', '-' => '-');
 
@@ -81,4 +81,32 @@ sub doMilScan ($$$) {
        }
 }
 
+my $addplanetscan_sql = q{INSERT INTO planet_scans
+       (id,tick,pid,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium
+               ,agents,guards,light,medium,heavy,hidden)
+       VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)};
+
+sub doPlanetScan ($$$) {
+       my ($dbh, $scan,$file) = @_;
+
+       my $addplanetscan = $dbh->prepare_cached($addplanetscan_sql);
+
+       my @values = ($scan->{id},$scan->{tick},$scan->{pid});
+       $file =~ s/(\d),(\d)/$1$2/g;
+
+       while($file =~ m{"center">(Metal|Crystal|Eonium)</td>\D+(\d+)\D+([\d,]+)}g){
+               push @values,$2,$3;
+       }
+       if($file =~ m{Security\ Guards .+? "center">(\d+)</td>
+                       .+? "center">(\d+)</td>}sx){
+               push @values,$1,$2;
+       }
+       if($file =~ m{<td class="center">([A-Z][a-z]+)</td><td class="center">([A-Z][a-z]+)</td><td class="center">([A-Z][a-z]+)</td>}){
+               push @values,$1,$2,$3;
+       }
+       if($file =~ m{<span class="superhighlight">([\d,]+)</span>}){
+               push @values,$1;
+       }
+       $addplanetscan->execute(@values);
+}