Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
make frab.xml for YAPC::Okinawa 2018
use strict;
use warnings;
use JSON::PP qw(decode_json);
use XML::TreePP;
use LWP::Simple;
use utf8;
sub guid {
my $id = shift;
return
}
my $blank = { '#text' => undef };
my $date = '2018-03-03';
my $js = get('https://spreadsheets.google.com/feeds/list/1OzGOr1eAaZrRllMrT4TUbt-fRn1xuflFZHUK-4VsU0s/on6oryq/public/values?alt=json');
my $dat = decode_json $js;
my $entry = $dat->{feed}->{entry};
my @srcentry = @{extra()};
my %room;
for(@$entry){
my $e = extractgsx($_);
push @srcentry, $e;
}
for(@srcentry){
my $e = g2frab($_);
my $room = $e->{room};
push @{$room{$room}}, $e;
}
my @day;
for(sort keys %room){
my %r;
$r{'-name'} = $_;
$r{event} = $room{$_};
push @day, \%r;
}
my $day = {
'-index' => 1,
'-date' => $date,
'-start' => $date . 'T09:50:00+09:00',
'-end' => $date . 'T19:20:00+09:00',
room => \@day,
};
my $conference = {
acronym => 'yapcokinawa2018',
title => 'YAPC::Okinawa 2018 ONNASON',
start => $date,
end => $date,
days => 1,
timeslot_duration => '00:05',
};
my $xml = {
schedule => {
version => 'copy',
conference => $conference,
day => $day,
}
};
my $tpp = XML::TreePP->new;
$tpp->set(first_out => ["version"]);
$tpp->writefile('yapcokinawa2018.xml', $xml);
# 入力データから使う部分を切り出し
sub extractgsx {
my %e;
my $ee = shift;
for(keys %$ee){
if(/^gsx\$(.+)/){
$e{$1} = $ee->{$_}->{'$t'};
}
}
return \%e;
}
# frab形式に変換
sub g2frab {
my %e;
my $s = shift;
$e{'-guid'} = sprintf('00000000-0000-4000-8000-%012d', $s->{id});
$e{'-id'} = $s->{id};
$e{date} = sprintf '%sT%s:00+09:00', $date, $s->{startat};
$e{start} = $s->{startat};
{
$s->{talktime} =~ /(\d+)/;
$e{duration} = sprintf('00:%02d', $1);
}
$e{room} = $s->{trackid};
$e{slug} = 'slag_' . $s->{id};
$e{recording} = {
license => $blank,
optout => {
'#text' => 'false'
}
};
$e{title} = $s->{title};
$e{subtitle} = $blank;
$e{track} = $s->{trackid};
$e{type} = 'lecture';
$e{language} = 'ja';
$e{abstract} = $blank;
$e{description} = $s->{description};
$e{persons} = {
person => {
'-id' => $s->{id},
'#text' => $s->{author},
}
};
$e{links} = $blank;
return \%e;
}
# 追加データ
sub extra {
return [
{
id => 900,
startat => '09:50',
talktime => '10',
title => 'Opening',
trackid => 'track-a',
description => $blank,
author => '',
},
{
id => 1001,
startat => '10:00',
talktime => '40',
title => 'GUEST',
trackid => 'track-a',
description => $blank,
author => '石垣 憲一',
},
{
id => 901,
startat => '12:30',
talktime => '50',
title => 'スポンサーセッション',
trackid => 'track-a',
description => $blank,
author => '',
},
{
id => 1002,
startat => '13:30',
talktime => '40',
title => 'GUEST',
trackid => 'track-a',
description => $blank,
author => '新屋 良磨',
},
{
id => 1003,
startat => '16:00',
talktime => '95',
title => 'スペシャルセッション',
trackid => 'track-a',
description => $blank,
author => '',
},
{
id => 1004,
startat => '17:45',
talktime => '40',
title => 'Keynote',
trackid => 'track-a',
description => $blank,
author => '大沢 和宏',
},
{
id => 1005,
startat => '18:30',
talktime => '40',
title => 'スポンサーセッション&Lightning Talks',
trackid => 'track-a',
description => $blank,
author => '',
},
{
id => 999,
startat => '19:10',
talktime => '10',
title => 'Closing',
trackid => 'track-a',
description => $blank,
author => '',
},
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment