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

/lib/DDG/Spice/InTheaters.pm

https://github.com/robertbrook/zeroclickinfo-spice
Perl | 91 lines | 82 code | 7 blank | 2 comment | 2 complexity | a8b998ea07b641e26498b08d4297871c MD5 | raw file
  1. package DDG::Spice::InTheaters;
  2. # ABSTRACT: Show movies from Rotten Tomatoes.
  3. use DDG::Spice;
  4. primary_example_queries "movies";
  5. secondary_example_queries "movies in theaters", "currently in theaters", "i want to watch a movie";
  6. description "Current movies from Rotten Tomatoes";
  7. name "InTheaters";
  8. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/InTheaters.pm";
  9. icon_url "/i/www.rottentomatoes.com.ico";
  10. topics "entertainment";
  11. category "entertainment";
  12. attribution github => ['https://github.com/jagtalon','jagtalon'],
  13. twitter => ['http://twitter.com/juantalon','juantalon'];
  14. my $rating = '(?:g\s*|pg\s*|r\s*)?';
  15. triggers any => 'movie', 'movies', 'theaters', 'theatres', 'showing', 'something', 'watch', 'opening', 'see';
  16. spice from => '(.*?)/(.*)';
  17. spice to => 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/$1.json?country=$2&apikey={{ENV{DDG_SPICE_ROTTEN_APIKEY}}}&callback={{callback}}&page_limit=12&limit=12';
  18. # Uses $loc so needs to not cache back end.
  19. spice is_cached => 0;
  20. spice proxy_cache_valid => "418 1d";
  21. my %movies = (
  22. 'movies now showing' => 1,
  23. 'what can i watch?' => 1,
  24. 'movies opening' => 0,
  25. 'movies opening soon' => 0,
  26. 'watch a movie' => 1,
  27. 'opening soon in theaters' => 0,
  28. 'opening soon in theatres' => 0,
  29. 'opening movies' => 0,
  30. 'r movies opening' => 0,
  31. 'pg movies opening' => 0,
  32. 'pg-13 movies opening' => 0,
  33. 'g movies opening' => 0,
  34. 'see an r movie' => 1,
  35. 'see a pg movie' => 1,
  36. 'see a pg-13 movie' => 1,
  37. 'see a g movie' =>1,
  38. 'r movies opening soon' => 0,
  39. 'pg movies opening soon' => 0,
  40. 'pg-13 movies opening soon' => 0,
  41. 'g movies opening soon' => 0,
  42. 'i need to watch a movie' => 1,
  43. 'i deserve to watch a movie' => 1,
  44. 'i want to watch a movie' => 1,
  45. 'i want to watch an r movie' => 1,
  46. 'i want to watch a pg movie' => 1,
  47. 'i want to watch a pg-13 movie' =>1,
  48. 'i want to watch something' => 1,
  49. 'watch something' => 1,
  50. 'need to watch a movie' => 1,
  51. 'need to watch an r movie' => 1,
  52. 'need to watch a pg movie' => 1,
  53. 'need to watch a pg-13 movie' => 1,
  54. 'need to watch a g movie' => 1,
  55. 'watch an r movie' => 1,
  56. 'watch a pg movie' => 1,
  57. 'watch an pg-13 movie' => 1,
  58. 'watch a g movie' => 1,
  59. 'theaters' => 0,
  60. 'theatres' => 0,
  61. 'movies' => 1,
  62. 'r movies' => 1,
  63. 'pg movies' => 1,
  64. 'pg-13 movies' => 1,
  65. 'g movies' => 1,
  66. 'movies in theaters' => 1,
  67. 'r movies in theaters' => 1,
  68. 'pg movies in theaters' => 1,
  69. 'pg-13 movies in theaters' => 1,
  70. 'g movies in theaters' => 1,
  71. 'movies currently in theaters' => 1,
  72. 'movies currently in theatres' => 1,
  73. 'currently in theaters' => 1,
  74. 'currently in theatres' => 1,
  75. );
  76. handle query_lc => sub {
  77. return unless exists $movies{$_};
  78. if($movies{$_}) {
  79. return "in_theaters", $loc->country_code;
  80. } else {
  81. return "opening", $loc->country_code;
  82. }
  83. };
  84. 1;