#! /usr/bin/perl
use strict;
use warnings;
use Date::Manip;

# Parses players from our own HTML, to get the clubs and nationalities right.

print "begin;\n";

while (<>) {
	if (/^ \s* <td><a \s* href=".*\/player\.pl\?id=\d+"> (.*?) <\/a><\/td> \s* $/x) {
		my $nick = $1;
	
		chomp ($_ = <>);
		/<td> (.*?) <\/td>/x or die;
		my $country = $1;
	
		chomp ($_ = <>);
		/<td> (.*?) <\/td>/x or die;
		my $club = $1;

		print "UPDATE players SET\n";
		print "  country=(SELECT country FROM countries WHERE countryname='$country'),\n";
		print "  club=(SELECT club FROM clubs WHERE clubname='$club') WHERE nick='$nick';\n";
	}
}

printf "commit;\n";
