Only insert a song if it doesn't already exist.
[ccbs] / parse / parse-ddreurope-tournament.pl
index 5773f13..3539946 100644 (file)
@@ -41,9 +41,6 @@ while (<>) {
        if (/^ <tr><td \s* class=dtd> .*? class="link"> (.*?) <\/a> $/x) {
                $player = $1;
 
-               # Woot, evil
-               printf "INSERT INTO players SELECT nextval('players_player_seq') AS player, '%s' AS nick WHERE '%s' NOT IN ( SELECT nick FROM players );\n", $player, $player;
-               
                printf "INSERT INTO roundparticipation (tournament, round, parallel, player, position) VALUES (\n";
                print "   (SELECT tournament FROM tournaments WHERE tournamentname='$name'),\n";
                print "   $round, $group,\n";
@@ -140,6 +137,42 @@ while (<>) {
                print "  round=$round;\n";
        }
 
+       # First place
+       if (/A \s* well-earned \s* victory \s* for .*? class="link"> (.*?) <\/a> (?: , \s* who \s* got \s* (\d+) \s* point )?/x) {
+               my $nick = $1;
+               my $points = $2;
+
+               # Whoa :-)
+               $points = 'NULL' unless defined($points);
+
+               # Woot, evil
+               printf "INSERT INTO players SELECT nextval('players_player_seq') AS player, '%s' AS nick WHERE '%s' NOT IN ( SELECT nick FROM players );\n", $nick, $nick;
+               
+               print "INSERT INTO tournamentrankings (tournament, ranking, player, points) VALUES (\n";
+               print "   (SELECT tournament FROM tournaments WHERE tournamentname='$name'),\n";
+               print "   1,\n";
+               print "   (SELECT player FROM players WHERE nick='$nick'),\n";
+               print "   $points);\n";
+       }
+
+       # All other places
+       while (s/(\d+) (?: st | nd | rd | th ) \s* place: .*? class="link"> (.*?) <\/a> \s* (?: got \s* (\d+) \s* point )?//x) {
+               my $ranking = $1;       
+               my $nick = $2;
+               my $points = $3;
+
+               # Whoa :-)
+               $points = 'NULL' unless defined($points);
+
+               # Woot, evil
+               printf "INSERT INTO players SELECT nextval('players_player_seq') AS player, '%s' AS nick WHERE '%s' NOT IN ( SELECT nick FROM players );\n", $nick, $nick;
+               
+               print "INSERT INTO tournamentrankings (tournament, ranking, player, points) VALUES (\n";
+               print "   (SELECT tournament FROM tournaments WHERE tournamentname='$name'),\n";
+               print "   $ranking,\n";
+               print "   (SELECT player FROM players WHERE nick='$nick'),\n";
+               print "   $points);\n";
+       }       
 }
 
 printf "commit;\n";