MythTV Perl script

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");
 
G

Gunnar Hjalmarsson

Dennis said:
Can anyone tell me why this isn't working.

Did you ask Perl?

use strict;
use warnings;

(I don't know if that will help you in this case, but you shouldn't
ask here without having asked Perl first. ;-) )
 
T

Todd Stephens

Todd Stephens wrote in article
Not only is that an image file, but that URL does not even exist when I
click on it.

Hmm. Scratch that. I went up a level in the directory and saw how it says
it is not an image, so choose "save as". I did that, but it still shows as
being a jpeg image after downloading. Opening in emacs proves otherwise.
Have you tried downloading the file and redirecting the program to read the
local file rather than the remote location?
 
D

Dennis

mooseshoes said:


<<< This is a jpeg file. You can't extract showlist information from it.

Moose
[/QUOTE]


Actually its not a .jpg, it's a text file. If you were to copy and
paste and right click on the link, it saves it as a text file. Taking
off the showlist.jpg extension from the link will take you to the
beginning and you can see what it says. If it is actually a text file
then it should work but it's not. Thanks for the replies guys.
 
D

Dennis

Todd Stephens said:
Todd Stephens wrote in article


Hmm. Scratch that. I went up a level in the directory and saw how it says
it is not an image, so choose "save as". I did that, but it still shows as
being a jpeg image after downloading. Opening in emacs proves otherwise.
Have you tried downloading the file and redirecting the program to read the
local file rather than the remote location?

No I haven't. Thats exactly what I wanted to do. I now what it is that
I want to do but unfortunatly I don't know perl whatso ever. Sorry. If
anyone could show me and tell me where to put it (no pun intended) I
would surely appreciate it.
 
R

Randal L. Schwartz

Dennis> Can anyone tell me why this isn't working. This script is supposed to
Dennis> take this pay per view information off this webpage and put it into a
Dennis> MySQL database. Unfortunately it doesn't do that.

Are you the author? If not, did you ask the author first?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top