generate program html
[star2016] / star2016-program.pl
1 #!/usr/bin/perl
2 use autodie;
3 use warnings;
4 use strict;
5
6 use utf8;
7 use XML::Simple;
8 use Data::Dump qw(dump);
9
10 my $xs = XML::Simple->new();
11
12 my $stat;
13 my $abstracts;
14
15 my $xml;
16 open(my $fh, '<:encoding(utf-8)', 'contributions/all.xml');
17 {
18         local $/ = undef;
19         $xml = <$fh>;
20         close($fh);
21 }
22
23 #warn "---xml---", dump($xml), "---/xml---\n";
24
25 foreach my $xml ( split(/\Q<?xml\E/, $xml) ) {
26
27         next unless $xml;
28
29         $xml = '<?xml' . $xml;
30
31         my $abstract;
32
33         $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
34
35         warn "# abstract = ", dump($abstract);
36
37         my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract);
38         warn "# $id abstract = ", dump($abstract);
39
40         foreach my $k (qw( ContributionType )) {
41                 push @{ $stat->{$k}->{ $abstract->{$k}->[0] } }, $id;
42         }
43
44         if ( $abstract->{'ContributionType'}->[0] eq 'Symposium proposal' ) {
45                 my $t = $abstract->{Title}->[0];
46                 push @{ $stat->{_symposium}->{ $t } }, -$id;
47         }
48
49         if ( my $s = $abstract->{Symposium_title} ) {
50                 $s = $s->[0];
51                 push @{ $stat->{_symposium}->{$s} }, $id;
52         }
53
54         if ( exists $abstract->{PrimaryAuthor}->[0]->{FamilyName} ) {
55                 $stat->{_order_by}->{$id} = $abstract->{PrimaryAuthor}->[0]->{FamilyName}->[0];
56         }
57
58         $abstracts->{ $id } = $abstract;
59
60 }
61
62 #warn "# stat = ",dump($stat);
63
64 use Text::CSV;
65
66 my $csv = Text::CSV->new ( { binary => 1 } )  # should set binary attribute.
67         or die "Cannot use CSV: ".Text::CSV->error_diag ();
68
69 my @program;
70  
71 open my $fh, "<:encoding(utf8)", "session-code.csv" or die "csv: $!";
72 while ( my $row = $csv->getline( $fh ) ) {
73         warn dump($row);
74         push @program, $row;
75 }
76 $csv->eof or $csv->error_diag();
77 close $fh;
78
79 open(my $program_fh, '>', 'program.html');
80 print $program_fh qq{<table>\n};
81
82 foreach my $p ( sort { $a->[6] cmp $b->[6] || $a->[1] cmp $b->[1] } @program ) {
83         my $abstract = $abstracts->{ $p->[0] } || die "no abstract for ", $p->[0];
84         my $authors;
85         foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
86                 $authors .= '; ' . $a->{FamilyName}->[0] . ', ' . $a->{FirstName}->[0];
87         }
88         $authors =~ s/^; //;
89         print $program_fh "<tr><td>", join("</td><td>", $p->[1], $p->[6], $p->[0], $p->[4] . '<br>' . $authors), "</td></tr>\n";
90 }
91
92 close $program_fh;
93