Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created May 19, 2010 09:06
Show Gist options
  • Save lestrrat/406110 to your computer and use it in GitHub Desktop.
Save lestrrat/406110 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# 日本の祝日をGoogleから持ってくるスクリプト
#
# こちらも参照の事! http://gist.github.com/406170
use strict;
use LWP::UserAgent;
use POSIX qw(strftime);
use URI;
use JSON::XS;
use XML::LibXML;
use XML::LibXML::XPathContext;
use Time::Local;
sub get_holidays { my @holidays;
my $ua = LWP::UserAgent->new();
my $uri = URI->new('http://www.google.com/calendar/feeds/[email protected]
lendar.google.com/public/full-noattendees');
$uri->query_form({
'start-min' => sprintf('%04d-%02d-%02d', (localtime)[5] + 1900, 1, 1),
'start-max' => sprintf('%04d-%02d-%02d', (localtime)[5] + 1900, 12, 31),
});
my $res = $ua->get($uri);
my $p = XML::LibXML->new();
my $dom = $p->parse_string( $res->content );
my $xpc = XML::LibXML::XPathContext->new();
$xpc->registerNs('atom', "http://www.w3.org/2005/Atom");
$xpc->registerNs('gd', "http://schemas.google.com/g/2005" );
foreach my $entry ( $xpc->findnodes('/atom:feed/atom:entry', $dom) ) {
my $start = $entry->findvalue('gd:when/@startTime');
if ($start =~ /^(\d{4})-(\d{2})-(\d{2})$/) {
push @holidays, timelocal 0, 0, 0, int($3), int($2) - 1, int($1) - 1
900;
}
}
return sort @holidays;
}
print map { strftime("%Y-%m-%d\n", localtime($_)) } get_holidays();
@mattn
Copy link

mattn commented May 19, 2010

mozillaが提供しているカレンダの方が、精度がいいらしいです。
あと祝日名が日本語なので使えるかも。
http://gist.github.com/406170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment