]> git.sesse.net Git - ccbs/blob - parse/parse-ddreurope-tournament.pl
ccee272c6d4f414827c925eb97b6f4fc30c7b5cc
[ccbs] / parse / parse-ddreurope-tournament.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4 use Date::Manip;
5
6 # Parses tournament results from the DDR Europe result list
7
8 my $season = shift;
9 my $name;
10 die "Missing season (give on command line)." if (!defined($season));
11
12 print "begin;\n";
13
14 while (<>) {
15         if (/<h2> \s* (.*?) \s* <\/h2>/x) {
16                 $name = $1;
17                 next;
18         }
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>
24             /x) {
25                 my ($country, $location, $date, $mix, $system) = ($1, $2, $3, $4, $5);
26                 $mix =~ s/Euromix/EuroMix/;
27
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";
31                 print "    '$name',\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";
37                 print ");\n";
38         }
39 }
40
41 printf "commit;\n";