Created
January 4, 2012 14:03
-
-
Save hakobe/1560191 to your computer and use it in GitHub Desktop.
list your winter season animes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use utf8; | |
binmode STDOUT => 'utf8'; | |
use WebService::SyoboiCalendar; | |
use Config::Pit qw(pit_get); | |
use YAML; | |
use Perl6::Say; | |
use Text::Xslate; | |
my $config = pit_get("cal.syoboi.jp", require => { | |
user => "your username on Syoboi Calendar", | |
pass => "your password on Syoboi Calendar" | |
}); | |
my $syoboi = WebService::SyoboiCalendar->new($config); | |
my $results = $syoboi->search_program({ | |
range => '2011/12/30-2012/2/28', | |
fresh => 2, | |
}); | |
my $dow_to_youbi = { 1 => '月', 2 => '火', 3 => '水', 4 => '木', 5 => '金', 6 => '土', 7 => '日', }; | |
my $animes = []; | |
for my $result (@$results) { | |
my $p = $result->program; | |
my $t = $result->title; | |
my $start_time = $p->start_time; | |
my $month = $start_time->month; | |
my $day = $start_time->day; | |
my $dow = $start_time->day_of_week; | |
my $hour = $start_time->hour; | |
my $minute = $start_time->minute; | |
if ($hour < 6) { | |
$hour += 24; | |
my $d = $start_time->clone; | |
$d->subtract( days => 1 ); | |
$month = $d->month; | |
$day = $d->day; | |
$dow = $d->dow; | |
}; | |
$hour = sprintf("%02d", $hour); | |
$minute = sprintf("%02d", $minute); | |
push @$animes, { | |
title => $t->title, | |
url => $t->official_site_url, | |
ch => $p->ch_name, | |
start => { | |
month => $month, | |
day => $day, | |
dow => $dow_to_youbi->{$dow}, | |
dow_num => $dow, | |
hour => $hour, | |
minute => $minute, | |
}, | |
voice_actors => join ', ', splice(@{ $t->voice_actors }, 0, 5), | |
}; | |
} | |
my $xslate = Text::Xslate->new( | |
syntax => "TTerse", | |
); | |
my $template = do { local $/; <DATA> }; | |
print $xslate->render_string($template, { | |
animes => $animes, | |
}); | |
__DATA__ | |
<table> | |
<tr> | |
<th>放送日時</th><th>最速</th><th>放送局</th><th>作品タイトル</th><th>声優</th> | |
</tr> | |
[%- FOREACH anime IN animes -%] | |
<tr> | |
<td [% IF anime.start.dow_num == 7 %]class="sunday"[% END %]>[% anime.start.month %]月[% anime.start.day %]日 ([% anime.start.dow %]) [% anime.start.hour %]:[% anime.start.minute %]〜</td> | |
<td></td> | |
<td>[% anime.ch %]</td> | |
<td><a href="[% anime.url %]">[% anime.title %]</a></td> | |
<td class="voice-actors">[% anime.voice_actors %]</td> | |
</tr> | |
[%- END # FOREACH anime IN animes -%] | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment