PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/DDG/Spice/InTheaters.pm

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