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