Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > MythTV Perl script

Reply
Thread Tools

MythTV Perl script

 
 
Dennis
Guest
Posts: n/a
 
      09-27-2003
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,subtit le,category) VALUES
(?,?,?,?,?,"","")
});

$sqladd->execute($ChannelNum,$StartTime,$StopTime,@progt it[$ProgPoint],@progdesc[$ProgPoint]);
$dbh->commit;

}
}
$dbh->disconnect;
printf("done.\n");
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-27-2003
Dennis wrote:
> 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. )

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
 
Todd Stephens
Guest
Posts: n/a
 
      09-27-2003
Dennis wrote in article <(E-Mail Removed) >:

> 'http://www.geocities.com/paglierani/showlist.jpg');


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

--
Todd Stephens
ICQ# 3150790
"A witty saying proves nothing."
-Voltaire
 
Reply With Quote
 
Todd Stephens
Guest
Posts: n/a
 
      09-27-2003
Todd Stephens wrote in article
<Z8ldb.24886$(E-Mail Removed)>:

> 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?

--
Todd Stephens
ICQ# 3150790
"A witty saying proves nothing."
-Voltaire
 
Reply With Quote
 
Dennis
Guest
Posts: n/a
 
      09-27-2003
mooseshoes <(E-Mail Removed)> wrote in message news:<qykdb.3890$(E-Mail Removed) om>...
> <snip>
>
>
> > 'http://www.geocities.com/paglierani/showlist.jpg');

>
>
> <<< This is a jpeg file. You can't extract showlist information from it.
>
> Moose
>
>
>
> -----
> Look for decreasing temperatures this winter with the likelihood of warmer
> weather in the spring.



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.
 
Reply With Quote
 
Dennis
Guest
Posts: n/a
 
      09-28-2003
Todd Stephens <Huzzah!@Huzzah.com> wrote in message news:<Geldb.24888$(E-Mail Removed) >...
> Todd Stephens wrote in article
> <Z8ldb.24886$(E-Mail Removed)>:
>
> > 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?


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.
 
Reply With Quote
 
Randal L. Schwartz
Guest
Posts: n/a
 
      09-28-2003
>>>>> "Dennis" == Dennis <(E-Mail Removed)> writes:

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?
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<(E-Mail Removed)> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pre-build MythTV Linux PVR eats Windows MCE for breakfast Au79 Computer Support 0 12-16-2006 04:43 AM
MythTV - New zealand mirror GJ NZ Computing 3 02-12-2005 05:32 AM
MythTV - Handle 2 tuners The Hobbit NZ Computing 20 09-29-2004 11:31 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
Anyone here using MythTV? Graeme Woollett NZ Computing 7 07-14-2003 01:06 AM



Advertisments