Mingus Iamblichus has asked for the wisdom of the Perl Monks concerning the following question:

Yo! I just got this script but I can't quite get it to work. I am unclear on the usage at the command line. I am looking for theaters in the 95501 area code and i believe 392 is the theater number. Is the usage 'theater_rss.pl <392>' or 'theater_rss.pl 392'? Any disecction of this code would be helpful. Ideally. i need my hand held. Any one got the time to give me a step-by-step? Thanx.

#!/usr/bin/perl # theater_rss.pl #Accepts a Yahoo! Movies theater ID and prints # an RSS feed of currently playing movies. # Usage: theater_rss.pl <theater_ID> # # You can find theater IDs at Yahoo! Movies # at http://movies.yahoo.com/ use strict; use XML::RSS::SimpleGen; # Grab the incoming theater ID my $tid = join(' ', @ARGV) or die "Usage: theater_rss.pl <theater_ID>\ +n"; my $theater_title = "My favorite theater"; # Set the theater schedule URL my $url = "http://acid1.oa.yahoo.com/mbl/mov/tdet?tid=$tid"; # Download the schedule page my $content = get_url($url); # Find the theater name if ($content =~ m!<dl><dt>(.*?)</dt>!sg) { $theater_title = $1; } # Start the RSS Feed rss_new($url, "$theater_title Schedule"); rss_language('en'); rss_webmaster('insert your email address'); rss_daily(); # Set the regular expression to find data my $regex = '<table.*?>.*?mid=(.*?)">(.*?)</a></td>.*?'; $regex .= '<td>(.*?)</td>.*?</table>'; # Loop through the HTML, grabbing elements while ($content =~ m!$regex!sg) { # rss_item accepts url, title, description. my $url = "http://movies.yahoo.com/shop?d=hv&cf=info&id=$1"; rss_item($url, $2, $3); } # Warn if nothing was found die "No items in this content?! {{\n$_\n}}\nAborting" unless rss_item_count(); # Save the rss file as <theater_ID>.rss rss_save("$tid.rss"); exit;

Edited by planetscape - added code tags

  • Comment on Stripping Movie Showtimes from a text file and inserting them into a mysql DB
  • Download Code

Replies are listed 'Best First'.
Re: Stripping Movie Showtimes from a text file and inserting them into a mysql DB
by planetscape (Chancellor) on Apr 08, 2006 at 17:05 UTC

    FWIW, code shown above is from the O'Reilly book Yahoo! Hacks.

    planetscape
Re: Stripping Movie Showtimes from a text file and inserting them into a mysql DB
by McDarren (Abbot) on Apr 08, 2006 at 16:40 UTC
    Is the usage 'theater_rss.pl <392>' or 'theater_rss.pl 392'?
    It would almost certainly be the latter.

    Strictly speaking, it should be "/path_to_script/script.pl parameters"

    So for example, if you have this script in /usr/local/bin, and you want to execute the script and pass 392 - you would type:

    /usr/local/bin/theater_rss.pl 392

    Cheers,
    Darren :)

Re: Stripping Movie Showtimes from a text file and inserting them into a mysql DB
by graff (Chancellor) on Apr 08, 2006 at 16:45 UTC

    So, I gather you did not write this code yourself. Do you know whether the person who did write this code would approve of having it posted publicly here? Was there any sort of copyright or license statement that came with this code? That sort of thing really matters.

    As for the usage, it is conventional in describing command line syntax to use different brackets to indicate whether a given arg is mandatory or optional, and the intention is that the user should not include those brackets when actually typing a command line. So your command line should look like this:

    theater_rss.pl 392
    i.e. without the angle brackets. (In fact, putting angle brackets on a command line usually means something special to the shell. If you don't know what that means, figure out what sort of shell you are using, and see if you can find a manual for how to use that shell. Look especially for "redirection".)

    As for step-by-step, it seems like the program code itself says pretty well what it is doing. After a successful run, you should be able to find relevant information in a file called "392.rss" in your current directory.

    (Oddly, it looks like the script will accept multiple theater-ids, and if the command line were  theater_rss.pl 392 393, then there would appearently be a file called "392 393.rss" -- note the space between the numbers is part of the file name.)

Re: Stripping Movie Showtimes from a text file and inserting them into a mysql DB
by helphand (Pilgrim) on Apr 09, 2006 at 18:41 UTC

    You won't get that script to work, Yahoo changed things on their side, the script will no longer work without extensive changes (url's changed and the parsing would require a complete rework).

    Scott

      Thanx Scott & company!! since this code is no longer compatible with Yahoo..does anyone know another method i could use to get movie showtimes