6 # Parses tournament results from the DDR Europe result list
9 my ($name, $round, @rsongs);
10 die "Missing season (give on command line)." if (!defined($season));
15 if (/<h2> \s* (.*?) \s* <\/h2>/x) {
19 if (/<br>Country: \s* (.*?) \s*
20 <br>Location: \s* (.*?) \s*
21 <br>Date: \s* (.*?) \s*
22 <br>Mix: \s* (.*?) \s*
23 <br>ScoringSystem: \s* (.*?) \s* <br>
25 my ($country, $location, $date, $mix, $system) = ($1, $2, $3, $4, $5);
26 $mix =~ s/Euromix/EuroMix/;
28 print "INSERT INTO tournaments \n";
29 print " (season, name, country, location, \"date\", machine, scoringsystem) VALUES (\n";
30 print " (SELECT season FROM seasons WHERE name='$season'),\n";
32 print " (SELECT country FROM countries WHERE name='$country'),\n";
33 print " '$location',\n";
34 printf " '%s',\n", Date::Manip::UnixDate($date, '%Y-%m-%d');
35 print " (SELECT machine FROM machines WHERE name='$mix'),\n";
36 print " (SELECT scoringsystem FROM scoringsystems WHERE name='$system')\n";
41 if (/<h3 \s* class=dthr> Round \s* (\d+) \s* <\/h3>/x) {
44 print "INSERT INTO rounds (tournament, round, randomsongs, chosensongs) \n";
46 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
48 print " 0, 0);\n"; # Don't worry, we'll fix it later :-P
51 # New group, and the random songs for it
52 if (/<th \s* class=dthp> ( Players | Group (\d+) )<\/th>/x) {
53 # bit of an evil hack here
55 $group = 0 if ($1 eq 'Players');
57 print "INSERT INTO groups (tournament, round, parallel) VALUES (\n";
58 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
59 print " $round, $group);\n";
61 # Find the random songs, if any
64 while (s/<th \s* class=dthpsong> .*? "color:white"> (.*?) <\/a><\/th>//x) {
67 print "INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (\n";
68 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
69 print " $round, $group,\n";
70 print " (SELECT song FROM songs WHERE title='$1')\n";
74 # Correct the random songs in the table
75 printf "UPDATE rounds SET randomsongs=%u WHERE \n", scalar @rsongs;
76 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
77 print " round=$round;\n";
80 # Header for chosen song
81 if (/<th \s* class=dthp \s* colspan=2> <\/th>/x) {
82 printf "UPDATE rounds SET chosensongs=chosensongs+1 WHERE \n";
83 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
84 print " round=$round;\n";