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