
use diagnostics;
use strict;

use Getopt::Std;
use HamScrape;

my $help = <<"EOH";
---------------------------------------------------------------------------
Command help for the findu.com Web scraper

Options: -h   This help
         -s   callsign
         -x   Emit as XML
         -f   Capture to file
EOH

my %args; getopts('hxfs:', \%args);
die $help if exists $args{h};
die $help unless $args{s};

if (exists $args{x}) {

	my $aprsXml = HamScrape::FindUXml($args{s});
	if (exists $args{f}) {
		HamScrape::WriteXmlTreeToFile($aprsXml);

	} else {
		print $aprsXml;
	} 

} else {

	my %aprs = HamScrape::FindU($args{s});
	if (exists $args{f}) {
		HamScrape::WriteRawTextToFile(%aprs);
		
	} else {
		my $callsign = $aprs{Callsign};
		my $lastHeard = $aprs{LastHeard};
		my $status = $aprs{Status};
		 
		print "Callsign: $callsign\n";
		print "Last heard: $lastHeard\n";
		print "Status: $status\n";
	}

}