Last active
August 29, 2015 14:02
-
-
Save onishi/72f09b5be34f809f766b to your computer and use it in GitHub Desktop.
QUERY_STRINGにドメイン入れるとical形式でリマインダのカレンダー吐いてくれるの
This file contains hidden or 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 Net::Domain::ExpireDate 'expire_date'; | |
use Time::Seconds; | |
use Data::ICal; | |
use Data::ICal::Entry::Todo; | |
use Data::ICal::Entry::Event; | |
use Date::ICal; | |
my $app = sub { | |
my $env = shift; | |
my @domains = split(/,/, $env->{QUERY_STRING}); | |
my $calendar = Data::ICal->new; | |
for my $domain (@domains) { | |
my $expire = expire_date($domain) or next; | |
for my $prev_day (qw/0 1 7 30 60 365/) { | |
my $t = $expire - (ONE_DAY * $prev_day); | |
my $new_event = Data::ICal::Entry::Event->new(); | |
$new_event->add_properties( | |
summary => sprintf("%s expire in %d days (%s)", $domain, $prev_day, $expire->ymd), | |
dtstart => sprintf("%04d%02d%02d", $t->year, $t->mon, $t->mday), | |
dtend => sprintf("%04d%02d%02d", $t->year, $t->mon, $t->mday), | |
); | |
$calendar->add_entry( $new_event ); | |
} | |
} | |
my $content = $calendar->as_string; | |
return [ | |
'200', | |
#[ 'Content-Type' => 'text/calendar; charset=utf-8' ], | |
[ 'Content-Type' => 'text/plain; charset=utf-8' ], | |
[ $content ], | |
]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment