D
Dennis
Can anyone tell me why this isn't working. This script is supposed to
take this pay per view information off this webpage and put it into a
MySQL database. Unfortunately it doesn't do that. All it does is give
me the readout that it has downloaded and updated and give me one
single record that is of no use to me. All of the modules have been
installed. Oh, I am a newbie but am willing to learn. Any help at all
would be greatly appreciated. Thanks
#!/usr/bin/perl
package main;
# Load required stuffs
use HTTP::Request;
use LWP::UserAgent;
use POSIX qw(strftime);
use DBI;
if(@ARGV[0] != 1 && @ARGV[0] != 2){printf("Please use either \"1\"
(delete) or \"2\" (update)\n");exit();}
if(@ARGV[0] == 1){
printf("Deleting all PPV Database entries...");
my $dbh = DBI->connect("dbi:mysql:mythconverg:127.0.0.1", mythtv,
mythtv, {
RaiseError => 1, AutoCommit => 0
});
my $sqldel = $dbh->prepare( q{
DELETE FROM program WHERE chanid > 1100 AND chanid < 1200
});
$sqldel->execute();
$dbh->commit;
$dbh->disconnect;
printf("done.\n");
exit();
}
my $dbh = DBI->connect("dbi:mysql:mythconverg:127.0.0.1", mythtv,
mythtv, {
RaiseError => 1, AutoCommit => 0
});
# Get the webpage (note: webpage is hardcoded)
printf("Downloading PPV information...");
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request(GET =>
'http://www.geocities.com/paglierani/showlist.jpg');
my $response = $ua->request($request);
printf("done.\n");
printf("Updating database with PPV information...");
# For each line, look to see if it begins sections; process sections
accordingly
# Sections are: channels (has channels) ; shows (has shows)
foreach (split /\r\n/, $response->content()) {
if ($_ eq "proc addChannels { } {")
{
$addchans = 1;
}
elsif ($_ eq "proc addPrograms { } {")
{
$addprogs = 1;
}
if ($addchans == 1 && $_ ne "proc addChannels { } {" and $_ ne "}")
{
$_ =~ s/^\S+\s+//;
$channum = substr($_, 3);
$channum =~ s/\s+$//;
}
elsif ($addprogs == 1 && $_ ne "proc addPrograms { } {" && $_ ne "}")
{
($foo1, $ProgramID, $foo3, $SingTitle, $foo5) = split ' ', $_;
(@ProgramArray) = split '{', $_;
($ProgramTitle, $ProgramDescription) = @ProgramArray[1,-1];
if (index($SingTitle, '{') == -1) {
$ProgramTitle = $SingTitle;
}
else{
($ProgramTitle) = split '}', $ProgramTitle;
}
($ProgramDescription) = split '}', $ProgramDescription;
$ProgramID = substr($ProgramID,2);
@progtit[$ProgramID] = $ProgramTitle;
@progdesc[$ProgramID] = $ProgramDescription;
}
#Turn off section designations, which stops processing the section.
if ($_ eq "}" && $addchans == 1 ) {
$addchans = 0;
}
elsif ($_ eq "}" && $addprogs == 1 ) {
$addprogs = 0;
}
}
foreach (split /\r\n/, $response->content()) {
if ($_ eq "proc addPrograms { } {")
{
$addprogs = 1;
}
if (index($_, 'ads ') != -1 && $addprogs != 1) {
(@RawPrograms) = split ' ', $_;
($ChannelNum, $ProgDate, $ProgStart, $ProgDur, $ProgPoint) =
@RawPrograms[2,3,4,5,6];
$ProgPoint = substr($ProgPoint, 2);
$ChannelNum = substr($ChannelNum, 3) + 1000;
$ProgStart = $ProgDate * 86400 + $ProgStart;
$ProgStop = $ProgStart + $ProgDur;
$StartTime = strftime ("%Y%m%d%H%M%S %Z", localtime($ProgStart));
$StopTime = strftime ("%Y%m%d%H%M%S %Z", localtime($ProgStop));
my $sqladd = $dbh->prepare( q{
INSERT INTO program
(chanid,starttime,endtime,title,description,subtitle,category) VALUES
(?,?,?,?,?,"","")
});
$sqladd->execute($ChannelNum,$StartTime,$StopTime,@progtit[$ProgPoint],@progdesc[$ProgPoint]);
$dbh->commit;
}
}
$dbh->disconnect;
printf("done.\n");
take this pay per view information off this webpage and put it into a
MySQL database. Unfortunately it doesn't do that. All it does is give
me the readout that it has downloaded and updated and give me one
single record that is of no use to me. All of the modules have been
installed. Oh, I am a newbie but am willing to learn. Any help at all
would be greatly appreciated. Thanks
#!/usr/bin/perl
package main;
# Load required stuffs
use HTTP::Request;
use LWP::UserAgent;
use POSIX qw(strftime);
use DBI;
if(@ARGV[0] != 1 && @ARGV[0] != 2){printf("Please use either \"1\"
(delete) or \"2\" (update)\n");exit();}
if(@ARGV[0] == 1){
printf("Deleting all PPV Database entries...");
my $dbh = DBI->connect("dbi:mysql:mythconverg:127.0.0.1", mythtv,
mythtv, {
RaiseError => 1, AutoCommit => 0
});
my $sqldel = $dbh->prepare( q{
DELETE FROM program WHERE chanid > 1100 AND chanid < 1200
});
$sqldel->execute();
$dbh->commit;
$dbh->disconnect;
printf("done.\n");
exit();
}
my $dbh = DBI->connect("dbi:mysql:mythconverg:127.0.0.1", mythtv,
mythtv, {
RaiseError => 1, AutoCommit => 0
});
# Get the webpage (note: webpage is hardcoded)
printf("Downloading PPV information...");
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request(GET =>
'http://www.geocities.com/paglierani/showlist.jpg');
my $response = $ua->request($request);
printf("done.\n");
printf("Updating database with PPV information...");
# For each line, look to see if it begins sections; process sections
accordingly
# Sections are: channels (has channels) ; shows (has shows)
foreach (split /\r\n/, $response->content()) {
if ($_ eq "proc addChannels { } {")
{
$addchans = 1;
}
elsif ($_ eq "proc addPrograms { } {")
{
$addprogs = 1;
}
if ($addchans == 1 && $_ ne "proc addChannels { } {" and $_ ne "}")
{
$_ =~ s/^\S+\s+//;
$channum = substr($_, 3);
$channum =~ s/\s+$//;
}
elsif ($addprogs == 1 && $_ ne "proc addPrograms { } {" && $_ ne "}")
{
($foo1, $ProgramID, $foo3, $SingTitle, $foo5) = split ' ', $_;
(@ProgramArray) = split '{', $_;
($ProgramTitle, $ProgramDescription) = @ProgramArray[1,-1];
if (index($SingTitle, '{') == -1) {
$ProgramTitle = $SingTitle;
}
else{
($ProgramTitle) = split '}', $ProgramTitle;
}
($ProgramDescription) = split '}', $ProgramDescription;
$ProgramID = substr($ProgramID,2);
@progtit[$ProgramID] = $ProgramTitle;
@progdesc[$ProgramID] = $ProgramDescription;
}
#Turn off section designations, which stops processing the section.
if ($_ eq "}" && $addchans == 1 ) {
$addchans = 0;
}
elsif ($_ eq "}" && $addprogs == 1 ) {
$addprogs = 0;
}
}
foreach (split /\r\n/, $response->content()) {
if ($_ eq "proc addPrograms { } {")
{
$addprogs = 1;
}
if (index($_, 'ads ') != -1 && $addprogs != 1) {
(@RawPrograms) = split ' ', $_;
($ChannelNum, $ProgDate, $ProgStart, $ProgDur, $ProgPoint) =
@RawPrograms[2,3,4,5,6];
$ProgPoint = substr($ProgPoint, 2);
$ChannelNum = substr($ChannelNum, 3) + 1000;
$ProgStart = $ProgDate * 86400 + $ProgStart;
$ProgStop = $ProgStart + $ProgDur;
$StartTime = strftime ("%Y%m%d%H%M%S %Z", localtime($ProgStart));
$StopTime = strftime ("%Y%m%d%H%M%S %Z", localtime($ProgStop));
my $sqladd = $dbh->prepare( q{
INSERT INTO program
(chanid,starttime,endtime,title,description,subtitle,category) VALUES
(?,?,?,?,?,"","")
});
$sqladd->execute($ChannelNum,$StartTime,$StopTime,@progtit[$ProgPoint],@progdesc[$ProgPoint]);
$dbh->commit;
}
}
$dbh->disconnect;
printf("done.\n");