Skip to content

Instantly share code, notes, and snippets.

@jberger
Created July 13, 2012 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/3102219 to your computer and use it in GitHub Desktop.
Save jberger/3102219 to your computer and use it in GitHub Desktop.
Webservice based holiday finder
#!/usr/bin/env perl
use strict;
use warnings;
use DateTime;
use DateTime::Format::Flexible;
my $t = DateTime->now;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
sub dt_from ($) { DateTime::Format::Flexible->parse_datetime( shift ) }
my $service = 'http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx/GetHolidaysForMonth';
my $query = {
countryCode => 'UnitedStates',
month => $t->mon,
year => $t->year,
};
my @dates = $ua->post_form( $service => $query )
->res
->dom
->find('Holiday')
->grep(sub{$_->at('DateType')->text eq 'Actual'})
->map(sub{ [ $_->at('Descriptor')->text, dt_from $_->at('Date')->text ] })
->each;
use Data::Dumper;
print Dumper \@dates;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment