+ # 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, ( SELECT country FROM countries WHERE countryname='Norway' ) AS country 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' AND season=( SELECT season FROM seasons WHERE seasonname='$season' )),\n";
+ print " 1,\n";
+ print " (SELECT player FROM players WHERE nick='$nick'),\n";
+ print " $points);\n";
+ }
+
+ # Odd split first places and stuff
+ if (/^ \s+ ( .*? \s+ and \s+ .*? <\/a>) \s+ won/x) {
+ my $winners = $1;
+ while ($winners =~ s/<a \s+ href= .*? class="link"> (.*?) <\/a>//x) {
+ my $nick = $1;
+ my $points = 'NULL';
+
+ printf "INSERT INTO players SELECT nextval('players_player_seq') AS player, '%s' AS nick, ( SELECT country FROM countries WHERE countryname='Norway' ) AS country 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' AND season=( SELECT season FROM seasons WHERE seasonname='$season' )),\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, ( SELECT country FROM countries WHERE countryname='Norway' ) AS country 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' AND season=( SELECT season FROM seasons WHERE seasonname='$season' )),\n";
+ print " $ranking,\n";
+ print " (SELECT player FROM players WHERE nick='$nick'),\n";
+ print " $points);\n";
+ }