#!/usr/local/bin/perl $| = 1; use Pg; $downloadOK = 1; $solarReport = ""; $mail_prog = '/usr/lib/sendmail' ; $theRootDir = "/home/hfradio/database/swl"; $theLogFile = $theRootDir . "/lookups.log"; $html_header = "Content-type: text/html\n\n"; $gmtTime = `date -u +%H:%M:%S`; chop $gmtTime; $showTime = `date -u +%H%M`; chop $showTime; $gmtDay = `date -u +%Y-%m-%d`; chop $gmtDay; $styleSheet = "/home/hfradio/html/cgi-bin/styles.format"; $theMenu = "/home/hfradio/html/cgi-bin/menu.format"; $theLinks = "shortwave links"; $remoteHost = $ENV{'REMOTE_HOST'}; &GetFormInput; doSolarData(); my ($result, $conn); my ($okToGoOn) = 1; my ($message) = ""; $conn = Pg::connectdb("dbname=swl user=tomas"); if (! PGRES_CONNECTION_OK eq $conn->status) { $okToGoOn = 0; $message = "Error hooking up to the database. Message is
"; $message .= $conn->errorMessage . "
\n"; print STDERR "No postgresql connection...\n"; print $html_header; print <Database Down for a while...
We are working with the database. This page is down for a while.
Please try again later. Thank you.
YE1 } else { @foundItems = (); %downloadList = (); if (exists ($field{'private'})) { $private = $field{'private'}; } if (! exists ($field{'search'})) { &showForm(1); } else { $theSearch = $field{'freq'}; $_theSearch = $theSearch; $_theSearch =~ s|^\s*(.*?)\s*$|$1|; if ($_theSearch =~ m|^voa$|i) { $_theSearch = "voice of america"; } $_theSearch =~ s/\%/\\\%/g; $_theSearch =~ s/\_/\\\_/g; $_theSearch =~ tr/A-Z/a-z/; $_theSearch = "\%" . $_theSearch . "\%"; print STDERR "Searching for [$_theSearch]\n"; $result = $conn->exec(" SELECT * FROM schedule_flat WHERE (LOWER(station) LIKE '$_theSearch') OR (LOWER(country) LIKE '$_theSearch') "); if (!PGRES_TUPLES_OK eq $result->resultStatus) { $okToGoOn = 0; $message = "Error getting the data out of the database. Message is
"; $message .= $conn->errorMessage . "
\n"; } else { while (@swl_field = $result->fetchrow) { my ($oid,$freq,$station,$utcTimeStart,$utcTimeEnd,$days,$lang,$country) = @swl_field; $freq =~ tr/ //d; $utcTimeStart =~ tr/\://d; $utcTimeStart =~ m|(\d\d\d\d)\d\d|; $utcTimeStart = $1; $utcTimeEnd =~ tr/\://d; $utcTimeEnd =~ m|(\d\d\d\d)\d\d|; $utcTimeEnd = $1; $count++; my $utcTime = $utcTimeStart . "-" . $utcTimeEnd; my $newRec = "$freq\t$utcTime\t$station\t$days\t$lang\t$country"; if (length($field{'lang'})) { if ($lang =~ m|$field{'lang'}|i) { push (@foundItems, $newRec); } } else { push (@foundItems, $newRec); } } } my $count = @foundItems; if ($count) { $tt = "_freq__time__station__country__days__lang_\n"; $theTable = "
\n
\n"; $trh = $tt; $trh =~ s|||ig; $tRow =~ s||ig; $tRow =~ s||\n"; open (OUTSF, "> /hfradio/html/hfstation/$dlFileName"); foreach $sfreq (sort mySort keys (%downloadList)) { print OUTSF "$downloadList{$sfreq}\n"; } close (OUTSF); } $theTable .= "
||ig; $trh =~ s|_freq_|FREQ|ig; $trh =~ s|_time_|Time|ig; $trh =~ s|_station_|Station|ig; $trh =~ s|_country_|Country|ig; $trh =~ s|_lang_|Language|ig; $trh =~ s|_days_|Days|ig; $theTable .= $trh; $tnum = 0; $color = 0; foreach $stationRec (sort mySort (@foundItems)) { my ($tRow) = $tt; my ($freq,$utcTime,$station,$days,$lang,$country) = split(/\t/, $stationRec); $tnum++; if ($color == 0) { $tRow =~ s|
||ig; $color = 1; } else { $color = 0; } $utcTime =~ m|^(\d{4})[^\d]*(\d{4})$|imsg; my ($startTime_) = $1; my ($endTime_) = $2; #print STDERR "st_ = [$startTime_], et_ = [$endTime_]\n"; if ( (($showTime >= $startTime_) && ($showTime <= $endTime_)) || (($showTime >= $startTime_) && (($endTime_ < $startTime_) && ($endTime_ < $showTime))) || (($startTime_ > $endTime_) && ($endTime_ > $showTime)) ) { $freq = "$freq"; $utcTime = "$utcTime"; $station = "$station"; $country = "$country"; $lang = "$lang"; $days = "$days"; $tRow =~ s||
|ig; } $tRow =~ s|_freq_|$freq|ig; $tRow =~ s|_time_|$utcTime|ig; $tRow =~ s|_station_|$station|ig; $tRow =~ s|_country_|$country|ig; $tRow =~ s|_lang_|$lang|ig; $tRow =~ s|_days_|$days|ig; $theTable .= $tRow; if ($downloadOK) { my ($newFreqL) = $freq; my ($newStation) = $station; $newFreqL =~ s|\.||g; $newFreqL =~ s|\||g; $newFreqL =~ s|\||g; $newFreqL =~ s|^(\d+?)(\d\d\d)(\d\d)$|$1\.$2|; $newStation =~ s|\||g; $newStation =~ s|\||g; $downloadList{$newFreqL} = "$newStation\t$newFreqL\tAM\t\t"; } } if ($downloadOK) { my ($rte_time) = `date -u +\"%Y-%d-%m_%H%M\"`; chop ($rte_time); my ($pid) = $$; my ($dlFileName) = "search_results" . "." . $pid . ".frq"; $theTable .= "

Shift-Click here to Download "; $theTable .= "Results for YPLog
\n"; } else { $theTable = "Nothing found for $theSearch
Try Station names, like, Voice of America, or WHRI, etc.
Searches like USA are too broad. Or, like RFI, use France. Try alternatives.
\n"; } &showForm(2); } } sub showForm { my ($option) = @_; my $what = ""; my $lastSearch = "Last Five Searched:
\n"; print $html_header; `tail -n 5 $theLogFile > $theLogFile.2.last`; open (RLOG, "$theLogFile.2.last"); while () { my $rLine = $_; if (m|Search\:\s+(.*)|i) { $what = $1; $lastSearch .= "$what
\n"; } } close (RLOG); open (STYLE, "$styleSheet") || die "Could not read $styleSheet: $!\n"; $_style = ""; while (