/lib/DDG/Spice/InTheaters.pm

https://github.com/pardocz/zeroclickinfo-spice · Perl · 107 lines · 98 code · 7 blank · 2 comment · 2 complexity · 5a1788eb9231043240898489f36da47f 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 => "200 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. 'pg13 movies opening' => 0,
  35. 'unrated movies opening' => 0,
  36. 'see an r movie' => 1,
  37. 'see a pg movie' => 1,
  38. 'see a pg-13 movie' => 1,
  39. 'see a g movie' =>1,
  40. 'see a pg13 movie' =>1,
  41. 'see an unrated movie' =>1,
  42. 'pg13 movies opening soon' => 0,
  43. 'unrated movies opening soon' => 0,
  44. 'r movies opening soon' => 0,
  45. 'pg movies opening soon' => 0,
  46. 'pg-13 movies opening soon' => 0,
  47. 'g movies opening soon' => 0,
  48. 'i need to watch a movie' => 1,
  49. 'i deserve to watch a movie' => 1,
  50. 'i want to watch a movie' => 1,
  51. 'i want to watch an r movie' => 1,
  52. 'i want to watch a pg movie' => 1,
  53. 'i want to watch a pg-13 movie' =>1,
  54. 'i want to watch a pg13 movie' =>1,
  55. 'i want to watch an unrated movie' =>1,
  56. 'i want to watch something' => 1,
  57. 'watch something' => 1,
  58. 'need to watch a movie' => 1,
  59. 'need to watch an r movie' => 1,
  60. 'need to watch a pg movie' => 1,
  61. 'need to watch a pg-13 movie' => 1,
  62. 'need to watch a g movie' => 1,
  63. 'need to watch a pg13 movie' => 1,
  64. 'need to watch an unrated movie' => 1,
  65. 'watch an r movie' => 1,
  66. 'watch a pg movie' => 1,
  67. 'watch a pg-13 movie' => 1,
  68. 'watch a g movie' => 1,
  69. 'watch a pg13 movie' => 1,
  70. 'watch an unrated movie' => 1,
  71. 'theaters' => 0,
  72. 'theatres' => 0,
  73. 'movies' => 1,
  74. 'r movies' => 1,
  75. 'pg movies' => 1,
  76. 'pg-13 movies' => 1,
  77. 'g movies' => 1,
  78. 'pg13 movies' => 1,
  79. 'unrated movies' => 1,
  80. 'movies in theaters' => 1,
  81. 'r movies in theaters' => 1,
  82. 'pg movies in theaters' => 1,
  83. 'pg-13 movies in theaters' => 1,
  84. 'g movies in theaters' => 1,
  85. 'pg13 movies in theaters' => 1,
  86. 'unrated movies in theaters' => 1,
  87. 'movies currently in theaters' => 1,
  88. 'movies currently in theatres' => 1,
  89. 'currently in theaters' => 1,
  90. 'currently in theatres' => 1,
  91. );
  92. handle query_lc => sub {
  93. return unless exists $movies{$_};
  94. if($movies{$_}) {
  95. return "in_theaters", $loc->country_code;
  96. } else {
  97. return "opening", $loc->country_code;
  98. }
  99. };
  100. 1;