generate odt from contributions
[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         my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
63         $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
64
65         foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
66                 $doc->appendParagraph(text => join(' ',
67                         map { $a->{$_}->[0] } qw( FirstName FamilyName Email Affiliation )
68                 ), style => 'Heading 2');
69                 push @{ $stat->{_Affiliation}->{ $a->{Affiliation}->[0] } }, $id;
70         }
71
72         $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
73         
74         $doc->appendParagraph(text => "Theme: " . $f->{2}->{'content'}, style => 'Theme');
75
76 }
77
78 warn "# stat = ",dump($stat);
79
80 $doc->save;
81