
use diagnostics;
use strict;

use Benchmark;
use Getopt::Std;
use HamScrape;

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

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

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

my $start = new Benchmark;

if (exists $args{x}) {

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

} else {

	my %aprs = HamScrape::APRSWorld($args{s});
	if (exists $args{f}) {
		HamScrape::WriteRawTextToFile(%aprs);

	} else {
		my $callsign = $aprs{Callsign};
		my $position = $aprs{Position};
		my $lastHeard = $aprs{LastHeard};
		my $status = $aprs{Status};
	 
		print "Callsign: $callsign\n";
		print "Position: $position\n";
		print "Last heard: $lastHeard\n";
		print "Status: $status\n";	

	}
}

my $stop = new Benchmark;
my $diff = timediff($stop, $start);

print "Time taken was", timestr($diff, 'all');
