#!/usr/bin/perl -w
use strict;
use Data::Dumper;

my %projects;

open LIST, "projects2010";
while (<LIST>) {
    chomp;
    my $file = $_;
    my ($project, $url, $name);
    open PAGE, $file;
    while (<PAGE>) {
	if (/(Název projektu|Project name)[:* ]*(.*)/) {
	    $project = $2;
	}
	if (/(Domovská stránka projektu|Project home ?page)[:* ]*<(.*)>/) {
	    $url = $2;
	}
	if (/\[\[!meta title="([^"]*)"\]\]/) {
	    $name = $1;
	}
    }

    if (!$projects{$project}) {
	$projects{$project} = {};
	$projects{$project}{'students'} = [];
    }
    my $p = $projects{$project};
    $$p{'url'} = $url;
    push @{$$p{'students'}}, { 'file' => $file, 'name' => $name };
}

print '[[!meta title="Projekty"]]', "\n";


foreach (sort(keys(%projects))) {
    print "\n* [$_](", $projects{$_}{'url'}, ")\n";
    #print Dumper($projects{$_}{'students'});
    foreach (@{$projects{$_}{'students'}}) {
	my $login = $_->{'file'};
	$login =~ s,/.*,,;
	my $name = $_->{'name'} || "???"; #$login;
	
	print "  * [[", $name || "", "|student/", $login, "]]\n";
    }
}
