]> ruin.nu Git - ndwebbie.git/blobdiff - scripts/scans.pl
Parse factory usage
[ndwebbie.git] / scripts / scans.pl
index 32e406e66d1174eaff1ab1aa6ff3b0a455ff041e..b4fe22df766f589e9840d470ae8036a2f64a1b24 100755 (executable)
@@ -78,6 +78,8 @@ my $addpdata = $dbh->prepare(q{INSERT INTO planet_data (id,tick,scan,rid,amount)
 $dbh->begin_work or die 'No transaction';
 $newscans->execute or die $dbh->errstr;
 $dbh->pg_savepoint('scans') or die "No savepoint";
+
+my %production = (None => 0, Low => 35, Medium => 65, High => 100);
 while (my $scan = $newscans->fetchrow_hashref){
        my $file = get("http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}");
        next unless defined $file;
@@ -106,14 +108,32 @@ while (my $scan = $newscans->fetchrow_hashref){
                }
                if ($type eq 'Planet'){
                        $file =~ s/(\d),(\d)/$1$2/g;
-                       while($file =~ m/"left">(Metal|Crystal|Eonium)\D+(\d+)\D+(\d+)/g){
+                       while($file =~ m/"center">(Metal|Crystal|Eonium)\D+(\d+)\D+([\d,]+)/g){
+                               my ($roids,$res) = ($2,$3);
+                               $roids =~ s/,//g;
+                               $addpdata->execute($planet,$tick,$scan->{id}
+                                       ,'roid',$1, $roids) or die $dbh->errstr;
+                               $res =~ s/,//g;
+                               $addpdata->execute($planet,$tick,$scan->{id}
+                                       ,'resource',$1, $res) or die $dbh->errstr;
+                       }
+                       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>}){
                                $addpdata->execute($planet,$tick,$scan->{id}
-                                       ,'roid',$1, $2) or die $dbh->errstr;
+                                       ,'planet','Light Usage', $production{$1}) or die $dbh->errstr;
+                               $addpdata->execute($planet,$tick,$scan->{id}
+                                       ,'planet','Medium Usage', $production{$2}) or die $dbh->errstr;
+                               $addpdata->execute($planet,$tick,$scan->{id}
+                                       ,'planet','Heavy Usage', $production{$3}) or die $dbh->errstr;
+                       }
+                       if($file =~ m{<span class="superhighlight">([\d,]+)</span>}){
+                               my $res = $1;
+                               $res =~ s/,//g;
                                $addpdata->execute($planet,$tick,$scan->{id}
-                                       ,'resource',$1, $3) or die $dbh->errstr;
+                                       ,'planet','Production', $res) or die $dbh->errstr;
                        }
                }elsif ($type eq 'Jumpgate'){
-                       while ($file =~ m/(\d+):(\d+):(\d+)\D+"left"\>(Attack|Defend|Return)<\/td><td>([^<]*)<\/td><td>(\d+)\D+(\d+)/g){
+               #print "$file\n";
+                       while ($file =~ m{(\d+):(\d+):(\d+)\D+(Attack|Defend|Return)</td><td class="left">([^<]*)\D+(\d+)\D+(\d+)}g){
                                
                                my ($sender) = $dbh->selectrow_array($findplanet,undef,$1,$2,$3,$tick) or die $dbh->errstr;
                                ($sender) = $dbh->selectrow_array($findoldplanet,undef,$1,$2,$3,$tick) if ((not defined $sender) && $4 eq 'Return');
@@ -186,6 +206,7 @@ while (my $scan = $newscans->fetchrow_hashref){
                $addpoints->execute(-1,$scan->{uid}) if $scan->{uid} > 0;
        }
 }
+#$dbh->rollback;
 $dbh->commit;
 
 sub addfleet {
@@ -203,7 +224,7 @@ sub addfleet {
 
        my @ships;
        my $total = 0;
-       while(defined $ships && $ships =~ m{((?:[a-zA-Z]| )+)</td><td>(\d+)}sg){
+       while(defined $ships && $ships =~ m{((?:[a-zA-Z]| )+)</td><td(?: class="right")?>(\d+)}sg){
                $total += $2;
                push @ships, [$1,$2];
        }