Astro-SpaceTrack

 view release on metacpan or  search on metacpan

tools/modeldef  view on Meta::CPAN

use Getopt::Long 2.39;
use JSON;
use Pod::Usage;
use POSIX qw{ strftime };

our $VERSION = '0.181';

my %opt;

GetOptions( \%opt,
    qw{ files! username=s password=s },
    help => sub { pod2usage( { -verbose => 2 } ) },
) or pod2usage( { -verbose => 0 } );

my %desc;

my $cgi = CGI->new();
$cgi->charset( 'utf-8' );
my $json = JSON->new();
my $st = Astro::SpaceTrack->new();

unless ( $opt{files} ) {
    foreach my $attr ( qw{ password username } ) {
	defined $opt{$attr}
	    and $st->set( $attr => $opt{$attr} );
    }

    defined $opt{username}
	or defined $opt{password}
	or $st->set( identity => 1 );
}

my $title = 'Space Track Model Definitions';

print
#   $cgi->header( -charset => 'utf-8' ),
    $cgi->start_html( -title => $title, -style => { src => 'trw.css' } ),
    $cgi->h1( $title ), $cgi->p( <<"EOD" );
This is an expansion on the model definitions provided by version 2 of
the Space Track interface. It is generated by
@{[ Cwd::abs_path( $0 ) ]}
EOD

foreach my $class ( qw{ boxscore launch_site satcat gp_history gp } ) {

    my $model;
    if ( $opt{files} ) {
	local $/ = undef;	# Slurp mode.
	open my $fh, '<:encoding(utf-8)', "$class.got"
	    or die "Failed to open $class.got: $!\n";
	$model = $json->decode( <$fh> );
	close $fh;
    } else {
	my $resp = $st->spacetrack_query_v2(
	    basicspacedata	=> 'modeldef',
	    class		=> $class,
	    format		=> 'json',
	);
	$resp->is_success()
	    or die $resp->status_line();
	$model = $json->decode( $resp->content_decoded() );
    }

    print $cgi->h2( "Class $class" ), $cgi->start_dl();
    foreach my $field (
	sort { $a->{Field} cmp $b->{Field} }
	@{ $model->{data} }
    ) {
	my $name = $field->{Field};
	print $cgi->dt( $name );
	my $blurb = defined $desc{$class}{$name} ? $desc{$class}{$name} :
	    defined $desc{_}{$name} ? $desc{_}{$name} : 'Unknown.';
	$blurb =~ s/ \s* \n / /smxg;
	print $cgi->dd( $blurb, interpret_type( $field ) );
    }
    print $cgi->end_dl();
}

print $cgi->p( <<'EOD' );
The descriptions of the data types should be pretty much
self-explanatory. However:
EOD

print $cgi->ul(
    map { $cgi->li( $_ ) } <<'EOD',
<code>date</code> by itself means a calendar date (GMT), without a time
of day. The date is expressed as a numeric <code>year-month-day</code>
with the year being a four-digit Gregorian year, and the month and day
being two digits.
EOD
    <<'EOD',
<code>date and time</code> means both calendar date (GMT) and optional
time of day. The time of day is expressed as
<code>hour:minute:second</code>, with each field having two digits, and
separated from the date by a single space.
EOD
);

print $cgi->table(
    {
	class	=> 'nopadding',
	summary => 'revision information',
    },
    $cgi->Tr(
	$cgi->td( { class => 'right' }, 'Last revision:' ),
	$cgi->td( strftime( '%d-%b-%Y', localtime ) ),
    ),
);

print $cgi->end_html();

{
    my %interp;

    BEGIN {
	%interp = (
	    bigint	=> sub {
		return 'integer of 8 bytes';
	    },
	    char	=> sub {
		my ( $type, $width ) = @_;



( run in 0.549 second using v1.01-cache-2.11-cpan-39bf76dae61 )