Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer O'Reilly Perl script to a webpage... 1

Status
Not open for further replies.

xmaveric

Programmer
Joined
Jul 1, 2005
Messages
8
Location
US
I would like to be able to put this in my own php page where I can enter a theater ID had have it produce an RSS feed of the movie showtimes.

This is the Perl script:

If you look at the bottom of the page, there is a user who has already done this, but I want to host this on my own website.

I'm looking for step-by-step instructions on how to do this. I am familar with PHP, but not with Perl. I am using IIS6/PHP5/MySQL5. I have ActivePerl installed on the server. I need to know how to install the required module, and how to make the Perl script work with PHP.

Note: This might not even need PHP to work on the web server, if not, I just need to know how to make Perl create an RSS feed that can be linked to from anywhere on the internet.
 
Here's the script as a perl service for the web. Not tested, but I'm bored and stuck staying awake as I'm doing an installation for work. You'll need to work with your Service Provider to get that module installed though.

Code:
#!/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 [URL unfurl="true"]http://movies.yahoo.com/[/URL]

use strict;
use XML::RSS::SimpleGen;
use CGI qw/standard/;
use CGI::Carp qw/fatalsToBrowser/;

# Initialize CGI
my $cgi = new CGI;

#Grab all name value pairs from query
#make sure the theater ID is named 'tid'
#you can send other variables through here as well
#I've set up a return URL to pass the user to a new page
#named 'redirect' When this script completes
my $form = $cgi->Vars();

# Grab the incoming theater ID
#my $tid = join(' ', @ARGV) or die "Usage: theater_rss.pl <theater_ID>\n";
my $tid = $form{tid};

my $theater_title = "My favorite theater";

# Set the theater schedule URL
my $url = "[URL unfurl="true"]http://acid1.oa.yahoo.com/mbl/mov/tdet?tid=$tid";[/URL]

# 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 = "[URL unfurl="true"]http://movies.yahoo.com/shop?d=hv&cf=info&id=$1";[/URL]
	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");

#Sending user to a new page
print redirect($form{redirect});
exit;

Again, not tested, but it should work.

- George
 
a * for the insomniac :-P

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Awww, gee, thanks Paul, but if I had a choice, I'd have been asleep like normal people.

- George
 
Thank you for the script.

I host my own web server. I have tried to open PPM and type "search XML-RSS-SimpleGen" but it says no modules found. :(
 
Try searching for just RSS. I came up with a result in the Perl 5.8 repository (Not sure of your version of Perl).

- George
 
I had an outdated version of ActivePerl. The package installed perfectly.

When I run the script above, I get the following errors:
Global symbol "%form" requires explicit package name at C:\ line 27.
Global symbol "%form" requires explicit package name at C:\ line 67.
Execution of C:\ aborted due to compilation errors.
 
Strict pragmas are in use, so each variable has to be declared with a statement of "my" or "our" or "local" (my being the most common).

my $tid = $form{tid};

This line in the script makes a call to the hash %forms, but %forms was never declared previously in the script. The error is complaining about that fact. In reality, we don't want to use %forms because the $cgi->Vars() was called in scalar context. When it is called in scalar context, it returns a reference to a tied hash. So, we have a typo in $form{tid};

It should be:

my $tid = $form->{tid};


Hth,

Raklet
 
That's what I get for writing something at 3 AM while working.

- George
 
You'd want to do the same for the redirect statement at the end of the script.

- George
 
So this:

print redirect($form{redirect});

Should be:

print redirect($form->{tid};{redirect});

??
 
Not quite... it should be:

Code:
print redirect($form->{redirect});

- George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top