View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 5 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: make_atsc_chanconf.pl
PostPosted: Fri Apr 22, 2005 10:24 am 
Offline
Joined: Thu Sep 30, 2004 11:29 am
Posts: 2419
Location: Mechanicsburg, PA
I updated Angel Li's perl script that pulls data from antennaweb.org to help you make an ~/.azap/channels.conf. Between the original writing and now, antennaweb.org's form behavior changed, breaking the script.

I emailed Angel with the update, but I wanted to post it here, too, in case people needed immediate functionality.

Code:
#!/usr/bin/perl

# Angel Li sent me this script to help set up an
# ~/.azap/channels.conf file automagically.  This probably
# isn't the final version .

# 04/22/2005: Edits by Bob Igo (Bob@StormLogic.com) to adapt the script to the
# new behavior on antennaweb.

 use LWP;
 use HTML::Form;
 use XML::XPath;
 use XML::XPath::XMLParser;

 #
 # Center frequencies for NTSC channels
 #
 @ntsc = (
     0,  0,  57,  63,  69,  79,  85, 177, 183, 189,
    195, 201, 207, 213, 473, 479, 485, 491, 497, 503,
    509, 515, 521, 527, 533, 539, 545, 551, 557, 563,
    569, 575, 581, 587, 593, 599, 605, 611, 617, 623,
    629, 635, 641, 647, 653, 659, 665, 671, 677, 683,
    689, 695, 701, 707, 713, 719, 725, 731, 737, 743,
    749, 755, 761, 767, 773, 779, 785, 791, 797, 803,
 );

$ZIPCODE = 'txtZipcode';
$MARKETING = 'chkMarketing';
$SURVEYS = 'chkSurveys';

 $XML = 'stationXml';
 $WEBSITE = 'http://www.antennaweb.org/aw/welcome.aspx';

 $zipCode = $ARGV[0];
 unless ($zipCode) {
    die "Zipcode missing on the command line";
 }
 unless ($zipCode =~ /^\d\d\d\d\d$/) {
    die "Illegal zipcode: $zipCode";
 }

 $ua = LWP::UserAgent->new;
 push @{$ua->requests_redirectable}, 'POST';
 $response = $ua->get($WEBSITE);
 if ($response->is_success) {
    $form = HTML::Form->parse($response);
    $request = $form->click;
   $response2 = $ua->request($request);
    if ($response2->is_success) {
       $form2 = HTML::Form->parse($response2);
      $form2->param($ZIPCODE, $zipCode);
      $form2->param($MARKETING, "off");   
      $form2->param($SURVEYS, "off");

       $request2 = $form2->click;
       $response3 = $ua->request($request2);
       if ($response3->is_success) {
         $form3 = HTML::Form->parse($response3);
          $xml = $form3->value($XML);
          $xml =~ s/%22/\"/g;
          $xml =~ s/%2c/,/g;
          $xml =~ s/%2f/\//g;
          $xml =~ s/%3c/</g;
          $xml =~ s/%3d/=/g;
         $xml =~ s/%3e/>/g;
          $xml =~ s/\+/ /g;
          genConf($xml);
          exit(0);
       }
       else {
          print STDERR "Could not submit zipcode: $zipCode\n";
          die $response3->status_line;
       }
    }
    print STDERR "Could not reach zipcode page";
    die $response2->status_line;
 }
 else {
    print STDERR "Error reaching $WEBSITE\n";
    die $response->status_line;
 }

 sub genConf {
    my($xml) = @_;
    my($s);
    my($callSign);
    my($channel);
    my($c);
    my($psipChannel);
    my($freq);

   $xp = XML::XPath->new(xml => $xml);
    foreach $s ($xp->find('//Station[BroadcastType="D"]')->get_nodelist) {
    if ($s->find('LiveStatus')->string_value eq "1") {
       $callSign = $s->find('CallSign')->string_value;
       $callSign =~ s/-DT//;
       $channel = $s->find('Channel')->string_value; # Channel to tune
      $psipChannel = $s->find('PsipChannel')->string_value;

       if ($DEBUG) {
         print STDERR $callSign, "\t", $channel, " -> ", $psipChannel, "\n";
       }

      $psipChannel =~ s/\.\d+$//;
      $freq = $ntsc[$channel]*1000000;
       if ($freq) {
          print $callSign, ":", $freq, ":8VSB:0:0\n";
       }
    }
 }
 }
[/code]

_________________
KnoppMyth R5.5
MythiC Dragon v2.0
Join the KnoppMyth Frappr!


Top
 Profile  
 
PostPosted: Fri Apr 22, 2005 11:59 am 
Offline
Joined: Tue Dec 07, 2004 12:04 pm
Posts: 369
What prerequisites?

Code:
Can't locate XML/XPath.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at ./get_channels_from_antennaweb.sh line 12.
BEGIN failed--compilation aborted at ./get_channels_from_antennaweb.sh line 12.



Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 12:18 pm 
Offline
Joined: Thu Sep 30, 2004 11:29 am
Posts: 2419
Location: Mechanicsburg, PA
Good point :) I had to get XML-XPath from CPAN at http://search.cpan.org/dist/XML-XPath/XPath.pm, build it, and install it:

Code:
perl Makefile.PL
su
make install

_________________
KnoppMyth R5.5
MythiC Dragon v2.0
Join the KnoppMyth Frappr!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 2:31 pm 
Offline
Joined: Tue Dec 07, 2004 12:04 pm
Posts: 369
Confused for a minute, until I realized that there was a link to the Source and then a link to the archive and I needed the latter.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 23, 2005 3:30 pm 
Offline
Joined: Fri Sep 19, 2003 7:05 pm
Posts: 5088
Location: Fontana, Ca
apt-get install libxml-xpath-perl

_________________
cesman

When the source is open, the possibilities are endless!


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 77 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu