forked from duckduckgo/zeroclickinfo-goodies
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
package DDG::Goodie::ISO639; | |||
# ABSTRACT: ISO 639 language names and codes | |||
|
|||
use DDG::Goodie; | |||
use Locale::Language; | |||
|
|||
use constant WPHREF => "https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes"; | |||
|
|||
zci answer_type => "language"; | |||
|
|||
# TODO: support "iso 639" and "iso-639" | |||
triggers start => "iso639"; | |||
|
|||
handle remainder => sub { | |||
my ($lang, $code) = langpair(shift) or return; | |||
my $text = sprintf qq(%s (ISO 639-1 %s)), $lang, $code; | |||
my $html = sprintf qq(%s (<a href="%s">ISO 639-1 %s</a>)), $lang, WPHREF, $code; | |||
return $text, html => $html; | |||
}; | |||
|
|||
sub langpair { | |||
if (my $lang = code2language($_)) { | |||
return ($lang, language2code($lang)); | |||
} | |||
if (my $code = language2code($_)) { | |||
return (code2language($code), $code); | |||
} | |||
return; | |||
} | |||
|
|||
zci is_cached => 1; | |||
|
|||
1; |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
package DDG::Goodie::ParseCron; | |||
# ABSTRACT: Parsing Crontabs - Show next occurence of cron event in human-readable form. | |||
# Example input: | |||
# crontab 42 12 3 Feb Sat | |||
# Example output: | |||
# Event will start next at 12:42:00 on 2 Feb, 2013 | |||
# | |||
|
|||
use DDG::Goodie; | |||
use Schedule::Cron::Events; | |||
|
|||
my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | |||
my @day = qw(Mon Tue Wed Thu Fri Sat Sun); | |||
|
|||
triggers start => 'crontab'; | |||
zci is_cached => 0; | |||
handle remainder => sub { | |||
my $crontab = $_; | |||
# We replace Jan,Feb.. and Mon,Tue.. with 1,2.. | |||
foreach (0..$#mon) { | |||
my $newmonth=$_+1; | |||
$crontab =~ s/$mon[$_]/$newmonth/; | |||
} | |||
foreach (0..$#day) { | |||
my $newday=$_+1; | |||
$crontab =~ s/$day[$_]/$newday/; | |||
} | |||
my $cron = new Schedule::Cron::Events($crontab) or return; | |||
my ($sec, $min, $hour, $day, $month, $year) = $cron->nextEvent; | |||
$year = $year+1900; | |||
my $text = sprintf qq(Event will start next at %02d:%02d:%02d on %d %s, %d), $hour, $min, $sec, $day, $mon[$month], $year; | |||
return $text if $_; | |||
return; | |||
}; | |||
1; |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
#!/usr/bin/env perl | |||
use utf8; | |||
use strict; | |||
use warnings; | |||
use Test::More; | |||
use DDG::Test::Goodie; | |||
|
|||
zci is_cached => 1; | |||
|
|||
ddg_goodie_test( | |||
["DDG::Goodie::ISO639"], | |||
"iso639 ab" => test_zci( | |||
qq(Abkhazian (ISO 639-1 ab)), | |||
html => qq(Abkhazian (<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1 ab</a>)), | |||
answer_type => "language" | |||
), | |||
"iso639 english" => test_zci( | |||
qq(English (ISO 639-1 en)), | |||
html => qq(English (<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1 en</a>)), | |||
answer_type => "language" | |||
), | |||
"iso-639 en" => test_zci( | |||
qq(English (ISO 639-1 en)), | |||
html => qq(English (<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1 en</a>)), | |||
answer_type => "language" | |||
), | |||
"iso639 xyz" => undef, | |||
); | |||
|
|||
done_testing; |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
#!/usr/bin/env perl | |||
|
|||
use strict; | |||
use warnings; | |||
use Test::More; | |||
use DDG::Test::Goodie; | |||
|
|||
zci answer_type => 'parsecron'; | |||
zci is_cached => 0; | |||
|
|||
ddg_goodie_test( | |||
[qw( | |||
DDG::Goodie::ParseCron | |||
)], | |||
'crontab * */3 * * *' => test_zci(qr/^Event will start next at \d{2}:\d{2}:\d{2} on \d{1,2} [a-zA-Z]{3}, \d{4}$/), | |||
'crontab 42 12 3 Feb Sat' => test_zci(qr/^Event will start next at \d{2}:\d{2}:\d{2} on \d{1,2} [a-zA-Z]{3}, \d{4}$/), | |||
); | |||
|
|||
done_testing; | |||
|
|||
|