From 39b2c14b7c9883708fbc128992ddf41c17d0a4fd Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 9 May 2016 19:04:22 +0200 Subject: [PATCH] generate program html --- star2016-program.pl | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 star2016-program.pl diff --git a/star2016-program.pl b/star2016-program.pl new file mode 100755 index 0000000..11bb2e2 --- /dev/null +++ b/star2016-program.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl +use autodie; +use warnings; +use strict; + +use utf8; +use XML::Simple; +use Data::Dump qw(dump); + +my $xs = XML::Simple->new(); + +my $stat; +my $abstracts; + +my $xml; +open(my $fh, '<:encoding(utf-8)', 'contributions/all.xml'); +{ + local $/ = undef; + $xml = <$fh>; + close($fh); +} + +#warn "---xml---", dump($xml), "---/xml---\n"; + +foreach my $xml ( split(/\QXMLin( $xml, ForceArray => qw(PrimaryAuthor) ); + + warn "# abstract = ", dump($abstract); + + my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract); + warn "# $id abstract = ", dump($abstract); + + foreach my $k (qw( ContributionType )) { + push @{ $stat->{$k}->{ $abstract->{$k}->[0] } }, $id; + } + + if ( $abstract->{'ContributionType'}->[0] eq 'Symposium proposal' ) { + my $t = $abstract->{Title}->[0]; + push @{ $stat->{_symposium}->{ $t } }, -$id; + } + + if ( my $s = $abstract->{Symposium_title} ) { + $s = $s->[0]; + push @{ $stat->{_symposium}->{$s} }, $id; + } + + if ( exists $abstract->{PrimaryAuthor}->[0]->{FamilyName} ) { + $stat->{_order_by}->{$id} = $abstract->{PrimaryAuthor}->[0]->{FamilyName}->[0]; + } + + $abstracts->{ $id } = $abstract; + +} + +#warn "# stat = ",dump($stat); + +use Text::CSV; + +my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. + or die "Cannot use CSV: ".Text::CSV->error_diag (); + +my @program; + +open my $fh, "<:encoding(utf8)", "session-code.csv" or die "csv: $!"; +while ( my $row = $csv->getline( $fh ) ) { + warn dump($row); + push @program, $row; +} +$csv->eof or $csv->error_diag(); +close $fh; + +open(my $program_fh, '>', 'program.html'); +print $program_fh qq{\n}; + +foreach my $p ( sort { $a->[6] cmp $b->[6] || $a->[1] cmp $b->[1] } @program ) { + my $abstract = $abstracts->{ $p->[0] } || die "no abstract for ", $p->[0]; + my $authors; + foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) { + $authors .= '; ' . $a->{FamilyName}->[0] . ', ' . $a->{FirstName}->[0]; + } + $authors =~ s/^; //; + print $program_fh "\n"; +} + +close $program_fh; + -- 2.20.1
", join("", $p->[1], $p->[6], $p->[0], $p->[4] . '
' . $authors), "