PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/SunRiseSet.pm

http://github.com/duckduckgo/zeroclickinfo-spice
Perl | 51 lines | 39 code | 10 blank | 2 comment | 1 complexity | 521224c506e8d97791c1adf9056ccf7c MD5 | raw file
Possible License(s): Apache-2.0
  1. package DDG::Spice::SunRiseSet;
  2. use DDG::Spice;
  3. use YAML::XS 'LoadFile';
  4. use Text::Trim;
  5. spice to => 'http://api.xmltime.com/timeservice?accesskey={{ENV{DDG_SPICE_TIME_AND_DATE_ACCESSKEY}}}&secretkey={{ENV{DDG_SPICE_TIME_AND_DATE_SECRETKEY}}}&out=js&query=$1&time=1&tz=1&verbosetime=1&sun=1&version=1';
  6. spice wrap_jsonp_callback => 1;
  7. spice proxy_cache_valid => "12h";
  8. triggers startend => "sunset", "sunrise";
  9. triggers start =>
  10. "when is the sunrise",
  11. "when is the sunset",
  12. "when is sunrise",
  13. "when is sunset",
  14. "when does the sun rise",
  15. "when does the sun set",
  16. "when does sun rise",
  17. "when does sun set",
  18. "when will the sun rise",
  19. "when will the sun set",
  20. "when will sun rise",
  21. "when will sun set";
  22. my $capitals = LoadFile(share('capitals.yml'));
  23. handle remainder_lc => sub {
  24. my $q = $_;
  25. $q =~ s/\b(what|is|today|time|in|at)+\b//g;
  26. $q =~ s/(\,\s)+/ /g;
  27. $q = trim $q;
  28. return unless $q;
  29. if (my $caps = $capitals->{$q}) {
  30. # These are internally sorted by population,
  31. # so assume they want the big one for now.
  32. $q = string_for_search($caps->[0]);
  33. return $q;
  34. }
  35. return;
  36. };
  37. sub string_for_search {
  38. my $city_hash = shift;
  39. return join(' ', map { lc $city_hash->{$_} } (qw(city country_name)));
  40. }
  41. 1;