generate program html
[star2016] / star2016-abstracts.pl
1 #!/usr/bin/perl
2 use autodie;
3
4 use XML::Simple;
5 use Data::Dump qw(dump);
6 use utf8;
7
8 my $indico_xml = 'abstracts.xml';
9 my $odt_file   = 'abstracts.odt';
10
11 my $xs = XML::Simple->new();
12 my $tree;
13 {
14         open(my $fh, '<:raw', $indico_xml);
15         local $/ = undef;
16         my $xml = <$fh>;
17 #       warn dump($xml);
18         $tree = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
19 }
20
21 my $abstracts = delete $tree->{abstract};
22
23 warn "# tree = ", dump($tree);
24
25 use     OpenOffice::OODoc       2.101;
26 my $doc = odfDocument(file => $odt_file, create => 'text');
27
28 my $stat;
29 my $id2nr;
30
31 $doc->createStyle(
32         "Abstract",
33         family          => 'paragraph',
34 #       parent          => 'Default Style',
35 #       category        => 'auto',
36         properties      => {
37                 -area                   => 'paragraph',
38                 'fo:text-align' => 'justify'
39         }
40 );
41
42
43 my $nr = 0;
44 foreach my $abstract ( @$abstracts ) {
45
46         my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract);
47         warn "# $id abstract = ", dump($abstract);
48
49         foreach $k (qw( ContributionType )) {
50                 $stat->{$k}->{ $abstract->{$k}->[0] } ++;
51         }
52
53         my $f = $abstract->{field};
54
55         push @{ $stat->{_symposium}->{ $f->{1}->{'content'} } }, $id if exists $f->{1}->{content};
56         push @{ $stat->{_theme}->{     $f->{2}->{'content'} } }, $id if exists $f->{2}->{content};
57
58         $stat->{field}->{ $_ }++ foreach keys %$f;
59
60         $id2nr->{ $id } = $nr++;
61
62 warn "$nr";
63
64         my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
65         $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
66
67         foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
68                 $doc->appendParagraph(text => join(' ',
69                         map { $a->{$_}->[0] } qw( FirstName FamilyName Email Affiliation )
70                 ), style => 'Heading 2');
71                 push @{ $stat->{_Affiliation}->{ $a->{Affiliation}->[0] } }, $id;
72         }
73
74         $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
75         
76         $doc->appendParagraph(text => "\nTheme: " . $f->{2}->{'content'}, style => 'Theme');
77         
78
79         $doc->appendParagraph(text => "\nID: " . $abstract->{Id}->[0], style => 'Abstract');
80 }
81
82 warn "# stat = ",dump($stat);
83
84 $doc->save;
85
86
87 open(my $fh, '>', 'affiliation.csv');
88 foreach my $a ( sort keys %{ $stat->{_Affiliation} } ) {
89         print $fh '"',$a,'","',dump( $stat->{_Affiliation}->{$a} ), '"', "\n";
90 }
91