# This module knows all about movies. # # History/Notes # 2003.09.22 # - Now adds itself to the global module list # 2003.09.17 # - Added history section :) package VladimirBot::Movies; use strict; use Parse::Earley; #use LWP::Simple; use WWW::Mechanize; use HTML::TokeParser; # Here I push myself onto the module call stack push @VladimirBot::vladimir_module, 'Movies'; # Parse a sentence or decide its not for me sub parse { my $sentence = shift; if ($sentence =~ /movie info (.*)/i) { # if($sentence =~ /movie/i) # { # return movietimes(); # } elsif ($sentence =~ /movie info (.*)/i) { return movieInfo($1); } else { return 0; } } sub movieInfo { my $title = shift; my $out; my $grammer = <<'END_GRAMMER'; END_GRAMMER my $mech = WWW::Mechanize->new(); $mech->get('http://imdb.com/'); $mech->set_fields( 'for' => $title ); $mech->click_button(name => 'Go'); my $content = $mech->content(); =cut sub movietimes { my $out; my $content = get('http://movies.yahoo.com/showtimes/showtimes.html?z=86001&r=sim'); my $stream = HTML::TokeParser->new( \$content ) or die $!; my $tag; while($tag = $stream->get_tag('tr')) { last if($tag->[1]{bgcolor} eq 'white'); } # Okay, find the title while($tag = $stream->get_tag('tr')) { last if($tag->[1]{bgcolor} eq 'white'); } my $i; for($i = 0; $i<12; $i++) { $tag = $stream->get_tag('a'); my $title = $stream->get_trimmed_text('/a'); $stream->get_tag('small'); my $info = $stream->get_trimmed_text('/small'); $stream->get_tag('font'); my $times = $stream->get_trimmed_text('/font'); $out .= "\n$title - $info\n$times"; } return $out; } =cut 1;