#!/usr/local/bin/perl
$| = 1;
use Pg;
my ($getFreq) = $ARGV[0];
my ($result, $conn);
$conn = Pg::connectdb("dbname=swl user=tomas");
if (! PGRES_CONNECTION_OK eq $conn->status) {
	print "Error initializing - could not connect to swl\n";
	print $conn->errorMessage . "\n";
	exit;
}

$result = $conn->exec("
	SELECT *
	FROM schedule_flat
	WHERE
		freq = '5975.0'
");
#			oid
#			freq,
#			station
#			utc_time
#			days
#			lang
#			country
#200312146487         9845.00  Radio NEDERLAND 00:00:00 01:00:00 1234567 English Netherland ANTILLES NA Bonaire 250.000 350  AM  6819W 1213N Bonaire External Service

if (!PGRES_TUPLES_OK eq $result->resultStatus) {
	print "Error: " . $conn->errorMessage . "\n";
	exit;
} else {
	print "Got Results ok\n";
}

while (@swl_field = $result->fetchrow) {
#	print "@swl_field";
#	print "\n\n";
	my ($oid,$freq,$station,$utcTimeStart,$utcTimeEnd,$days,$lang,$country) = @swl_field;
	print "$freq: $station at $utcTimeStart in $lang from $country\n"
}
