PageRenderTime 63ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/Songkick/Geteventid.pm

https://github.com/robertbrook/zeroclickinfo-spice
Perl | 40 lines | 31 code | 7 blank | 2 comment | 4 complexity | 4a82aa0181db4a50165634feb1622678 MD5 | raw file
  1. package DDG::Spice::Songkick::Geteventid;
  2. use strict;
  3. use warnings;
  4. use DDG::Spice;
  5. name "Songkick Events";
  6. description "See upcoming concerts.";
  7. source "Songkick";
  8. primary_example_queries "concerts in Boston";
  9. secondary_example_queries "Boston concerts";
  10. category "entertainment";
  11. topics "entertainment", "everyday", "music";
  12. # FIXME Point to the duckduckgo repository on pull.
  13. code_url "https://github.com/bradcater/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Songkick/Events.pm";
  14. attribution github => ["https://github.com/bradcater", "Brad Cater"],
  15. twitter => ["https://twitter.com/bradcater", "bradcater"];
  16. triggers startend => "concert", "concerts";
  17. spice to => 'http://api.songkick.com/api/3.0/search/locations.json?apikey={{ENV{DDG_SPICE_SONGKICK_APIKEY}}}&per_page=1&query=$1&jsoncallback={{callback}}';
  18. handle remainder => sub {
  19. # If the query isn't blank, then use it for the API query.
  20. if (length($_) > 0) {
  21. if ($_ =~ /^(around|in|near) (.+)$/) {
  22. (my $loc = $2) =~ s/^the\sarea$//g;
  23. if (length($loc) > 0) {
  24. return $loc;
  25. }
  26. } else {
  27. return;
  28. }
  29. }
  30. my $location = join(", ", $loc->city, $loc->region_name, $loc->country_name);
  31. return $location;
  32. };
  33. 1;