2013-07-18 23:11:08 -07:00
|
|
|
package DDG::Goodie::POTUS;
|
|
|
|
# ABSTRACT: Returns requested President of the United States
|
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2013-07-18 23:11:08 -07:00
|
|
|
use DDG::Goodie;
|
2013-08-13 12:03:07 -07:00
|
|
|
use Lingua::EN::Numbers::Ordinate qw(ordsuf ordinate);
|
2013-07-24 12:05:53 -07:00
|
|
|
use Lingua::EN::Words2Nums;
|
2015-05-29 15:18:03 -07:00
|
|
|
use YAML::XS 'LoadFile';
|
2013-07-18 23:11:08 -07:00
|
|
|
|
2013-07-24 12:05:53 -07:00
|
|
|
triggers startend => 'potus';
|
2013-07-23 19:02:51 -07:00
|
|
|
triggers any => 'president of the united states', 'president of the us';
|
|
|
|
|
2014-10-07 01:45:04 -07:00
|
|
|
zci answer_type => 'potus';
|
|
|
|
zci is_cached => 1;
|
2013-07-18 23:26:25 -07:00
|
|
|
|
2013-07-19 19:43:14 -07:00
|
|
|
name 'POTUS';
|
|
|
|
description 'returns the President of the United States';
|
|
|
|
category 'reference';
|
|
|
|
topics 'trivia';
|
|
|
|
primary_example_queries 'potus 16';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/POTUS.pm';
|
2015-01-07 10:24:47 -08:00
|
|
|
attribution github => ['numbertheory', 'John-Peter Etcheber'],
|
|
|
|
twitter => ['jpscribbles', 'John-Peter Etcheber'];
|
2013-07-19 19:43:14 -07:00
|
|
|
|
2015-05-29 15:18:03 -07:00
|
|
|
my @presidents = @{LoadFile(share('presidents.yml'))};
|
2014-10-07 01:45:04 -07:00
|
|
|
my $prez_count = scalar @presidents;
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2013-07-23 19:02:51 -07:00
|
|
|
handle remainder => sub {
|
2014-10-07 01:45:04 -07:00
|
|
|
my $rem = shift;
|
|
|
|
$rem =~ s/
|
2013-07-24 12:05:53 -07:00
|
|
|
|who\s+(is|was)\s+the\s+
|
|
|
|
|^POTUS\s+
|
|
|
|
|\s+(POTUS|president\s+of\s+the\s+united\s+states)$
|
|
|
|
|^(POTUS|president\s+of\s+the\s+united\s+states)\s+
|
|
|
|
//gix;
|
|
|
|
|
2014-10-07 01:45:04 -07:00
|
|
|
my $num = ($rem =~ /^\d+$/) ? $rem : words2nums($rem) || $prez_count;
|
|
|
|
my $index = $num - 1;
|
|
|
|
return if $index < 0 or $index > $#presidents;
|
2013-07-18 23:11:08 -07:00
|
|
|
|
2014-10-07 01:45:04 -07:00
|
|
|
my $fact = ($num == $prez_count ? 'is' : 'was') . ' the';
|
2013-08-13 12:03:07 -07:00
|
|
|
|
2014-10-07 01:45:04 -07:00
|
|
|
my $POTUS = 'President of the United States';
|
|
|
|
my $the_guy = $presidents[$index];
|
|
|
|
my $which = ordinate($num);
|
2013-07-23 19:02:51 -07:00
|
|
|
|
2014-10-07 01:45:04 -07:00
|
|
|
return "$the_guy $fact $which $POTUS.",
|
|
|
|
structured_answer => {
|
|
|
|
input => [$which],
|
|
|
|
operation => $POTUS,
|
|
|
|
result => $the_guy,
|
|
|
|
};
|
2013-07-23 19:02:51 -07:00
|
|
|
};
|
2013-07-18 23:11:08 -07:00
|
|
|
|
|
|
|
1;
|
2013-07-23 20:26:35 -07:00
|
|
|
|