MythTV Perl script

Discussion in 'Perl Misc' started by Dennis, Sep 27, 2003.

  1. Dennis

    Dennis Guest

    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");
     
    Dennis, Sep 27, 2003
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Sep 27, 2003
    #2
    1. Advertising

  3. Dennis wrote in article <>:

    > '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
     
    Todd Stephens, Sep 27, 2003
    #3
  4. Todd Stephens wrote in article
    <Z8ldb.24886$>:

    > 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
     
    Todd Stephens, Sep 27, 2003
    #4
  5. Dennis

    Dennis Guest

    mooseshoes <> wrote in message news:<qykdb.3890$>...
    > <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.
     
    Dennis, Sep 27, 2003
    #5
  6. Dennis

    Dennis Guest

    Todd Stephens <Huzzah!@Huzzah.com> wrote in message news:<Geldb.24888$>...
    > Todd Stephens wrote in article
    > <Z8ldb.24886$>:
    >
    > > 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.
     
    Dennis, Sep 28, 2003
    #6
  7. >>>>> "Dennis" == Dennis <> 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
    <> <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!
     
    Randal L. Schwartz, Sep 28, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,590
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,865
  3. pj
    Replies:
    3
    Views:
    321
  4. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    154
    Paul Lalli
    Jan 5, 2005
  5. Replies:
    20
    Views:
    875
    Gunnar Hjalmarsson
    Jan 18, 2005
Loading...

Share This Page