I recently fell in love with a Seattle based public radio station, KEXP. I've found alot of new music artists from listening over the past few days , ok, it's only been 2 days. KEXP provides an 'up-to-the-minute' playlist of what they have played within the hour. I wanted a little more info on the artists than what they were giving me so I threw together a little script to access Google's DB and return the top 6 results on the band's name.
Nothing too fancy, but I'm hoping that someone can learn something from it.

-Silent11
#!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTML::TableExtract; use SOAP::Lite; use CGI; my ($cgi, $ua, $request, $response, $html, $body, $ts, $row, $Boogle, +$out); my $GoogleKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $cgi = CGI->new(); $Boogle = \&google; $ua = LWP::UserAgent->new; $ua->proxy('http', ''); # enter proxy if needs be / and set it for Soa +p too ... $request = HTTP::Request->new('GET', 'http://140.142.17.178/playdisp +.asp'); $response = $ua->request($request); $html = $response->as_string; $body = new HTML::TableExtract( headers => [('Time','Artist','Song title','Album title','Label','C +omments' )] ) -> parse($html); print $cgi->header, $cgi->start_html({-title=>'KEXP PLAYLIST',-style=>{src=>'playlis +t.css'}}), $cgi->start_table({-border=>0,-width=>900,-cellpadding=>4, -ce +llspacing=>1}); print $cgi->Tr({-class=>'head'},$cgi->td(['Time','Artist','Song','Albu +m','6 Related links from Google'])); foreach $ts ($body->table_states) { foreach $row ($ts->rows) { my ($Time,$Artist,$Song,$Album,$Label,$Comments) = @$row; print $cgi->Tr({-class=>'body'}, $cgi->td([$Time,$Artist,$Song,$Album,$Boogle->($Artist)])) + if length($Time) > 3; # some rows are empty } } sub google { my $param = shift; my @params = ($GoogleKey,$param, 0, 6, 0, '', 0, '', 'latin1', 'latin +1'); my $result = SOAP::Lite -> service("file:GoogleSearch.wsdl") -> doGoo +gleSearch(@params); $out = join "\n\t", map( { qq{ &bull; <a href="$_->{URL}">} . ($_-> +{title} || $_->{URL}) . qq{</a> <br />} } @{$result->{resultElements} +} ); return $out; } #ps - don't be surprised if you get no playlist at the top of the hour # they tend to be about one min behind the actual play-time. # # # <silent11> can I reference a sub via a scalar? # <cluka> Sure. If you have a sub named routine, # you can reference it via $s = \&routine. Then call like $s->(args)

In reply to Expanding online radio with Google's API by silent11

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.