PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/MassOnTime.pm

https://github.com/robertbrook/zeroclickinfo-spice
Perl | 49 lines | 37 code | 10 blank | 2 comment | 5 complexity | 82a478c78c672f3864e9d2ff146041e3 MD5 | raw file
  1. package DDG::Spice::MassOnTime;
  2. use DDG::Spice;
  3. primary_example_queries "Catholic masses near Pittsburgh", "Catholic adoration in Washington DC";
  4. secondary_example_queries "Catholic masses near me", "catholic churches nearby";
  5. description "Search for Catholic Religious Events";
  6. name "MassOnTime";
  7. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/MassOnTime.pm";
  8. icon_url "http://massontime.com/favicon.ico";
  9. topics "special_interest";
  10. category "reference";
  11. attribution github => ['https://github.com/astine','astine'];
  12. triggers any => "catholic";
  13. spice is_cached => 1;
  14. spice from => '([^/]*)/([^/]*)';
  15. spice to => 'http://massontime.com/nearest/$1/10/json?address=$2&api-key={{ENV{DDG_SPICE_MASSONTIME_APIKEY}}}';
  16. spice wrap_jsonp_callback => 1;
  17. handle query_lc => sub {
  18. my $event_type;
  19. my $address;
  20. if ($_ =~ /^catholic\s(church|parish|mass|confession|adoration|service)(s|es)?(\s+close\sby|\s+around|\s+in|\s+nearby|\s+near|\s+at)?\s*(.*)$/i) {
  21. $event_type = $1;
  22. $address = $4;
  23. } elsif ($_ =~ /^(.*)\s+catholic\s+(church|parish|mass|confession|adoration|service)(s|es)?$/i) {
  24. $event_type = $2;
  25. $address = $1;
  26. }
  27. else {
  28. return;
  29. }
  30. #MassOnTime API doesn't recognize 'church;, replace with 'parish'
  31. $event_type = "parish" if $event_type eq "church";
  32. #Handle blank addresses or 'me' using DDG location api
  33. if ($address =~ m/^(close|me|here|nearby)$/i or $address eq "" or not defined $address) {
  34. $address = lc(join(", ", $loc->city, $loc->region_name, $loc->country_name));
  35. return $event_type, $address, 'current', {is_cached => 0};
  36. }
  37. return $event_type, $address;
  38. };
  39. 1;