#!/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 koid, freq, station, utc_time_start, utc_time_end, days, lang, country
	FROM schedule_flat
	WHERE
		lang LIKE '%Eng%'
");

#	koid char (20) UNIQUE NOT NULL,
#	freq char (8) NOT NULL,
#	station varchar (60) NOT NULL,
#	utc_time_start time NOT NULL,
#	utc_time_end time NOT NULL,
#	days char (7),
#	lang varchar (50),
#	country varchar (30),
#	target varchar (30),
#	location varchar (40),
#	power varchar (20),
#	azimuth varchar (3),
#	remarks varchar (30),
#	modulation varchar (6),
#	longitude varchar (6),
#	latitude varchar (6),
#	region varchar (20),
#	program varchar (40),

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 to $utcTimeEnd in [$lang] from $country ($days)\n"
}
