Astro-SpaceTrack

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    sporadically, and the data appear to be unaffected.

  Try to address test failures in mccants() under older Windows (plus
    one under FreeBSD) due to unseekability of the handle produced by
    open my $fh, '+<', \( $resp->content() );

  Fix problem in the login() method detecting a Space Track login
    failure.

  Add method mccants() to access TLE, magnitude, and RCS data mainteined
    by Mike McCants on his web site. Because these do not get updated
    that often, there is a 'file' option which, if specified, caches the
    results and fetches them from the web only if the cache is stale.

  Add 'file' option (as above) to amsat() and celestrak_supplemental().

  Add cache_hit() and associated machinery to determine whether
    information came from the web or from a file.

  Add information on celestrak() catalog 'argos'.

lib/Astro/SpaceTrack.pm  view on Meta::CPAN


    return $self;
}

=for html <a name="amsat"></a>

=item $resp = $st->amsat ()

This method downloads current orbital elements from the Radio Amateur
Satellite Corporation's web page, L<https://www.amsat.org/>. This lists
satellites of interest to radio amateurs, and appears to be updated
weekly.

No Space Track account is needed to access this data, even if the
'direct' attribute is false. As of version 0.150 the setting of
the 'with_name' attribute is honored even if the 'direct' attribute is
true.

You can specify options as either command-type options (e.g.
C<< amsat( '-file', 'foo.dat' ) >>) or as a leading hash reference (e.g.
C<< amsat( { file => 'foo.dat' } ) >>). If you specify the hash

lib/Astro/SpaceTrack.pm  view on Meta::CPAN

'-', and the argument list will not be parsed for command-type options.
If you specify command-type options, they may be abbreviated, as long as
the abbreviation is unique. Errors in either sort result in an exception
being thrown.

The legal options are:

 -file
   specifies the name of the cache file. If the data
   on line are newer than the modification date of
   the cache file, the cache file will be updated.
   Otherwise the data will be returned from the file.
   Either way the content of the file and the content
   of the returned HTTP::Response object end up the
   same.

On a successful return, the response object will contain headers

 Pragma: spacetrack-type = orbit
 Pragma: spacetrack-source = amsat

lib/Astro/SpaceTrack.pm  view on Meta::CPAN

leading '-', and the argument list will not be parsed for command-type
options.  If you specify command-type options, they may be abbreviated,
as long as the abbreviation is unique. Errors in either sort result in
an exception being thrown.

The legal options are:

 -file
   specifies the name of the cache file. If the data
   on line are newer than the modification date of
   the cache file, the cache file will be updated.
   Otherwise the data will be returned from the file.
   Either way the content of the file and the content
   of the returned HTTP::Response object end up the
   same.

On success, the content of the returned object is the actual data,
unzipped and with line endings normalized for the current system.

If this method succeeds, the response will contain headers

lib/Astro/SpaceTrack.pm  view on Meta::CPAN


In order not to load the Space Track web site too heavily, data are
retrieved in batches of 200. Ranges will be subdivided and handled in
more than one retrieval if necessary. To limit the damage done by a
pernicious range, ranges greater than the max_range setting (which
defaults to 500) will be ignored with a warning to STDERR.

If you specify C<-json> and more than one retrieval is needed, data from
retrievals after the first B<may> have field C<_file_of_record> added.
This is because of the theoretical possibility that the database may be
updated between the first and last queries, and therefore taking the
maximum C<FILE> from queries after the first may cause updates to be
skipped. The C<_file_of_record> key will appear only in data having a
C<FILE> value greater than the largest C<FILE> in the first retrieval.

This method implicitly calls the C<login()> method if the session cookie
is missing or expired. If C<login()> fails, you will get the
HTTP::Response from C<login()>.

If this method succeeds, a 'Pragma: spacetrack-type = orbit' header is
added to the HTTP::Response object returned.

lib/Astro/SpaceTrack.pm  view on Meta::CPAN

    }
    return $default;
}

=for html <a name="update"></a>

=item $resp = $st->update( $file_name );

This method updates the named TLE file, which must be in JSON format. On
a successful update, the content of the returned HTTP::Response object
is the updated TLE data, in whatever format is desired. If any updates
were in fact found, the file is rewritten. The rewritten JSON will be
pretty if the C<pretty> attribute is true.

The file to be updated can be generated by using the C<-json> option on
any of the methods that accesses Space Track data. For example,

 # Assuming $ENV{SPACETRACK_USER} contains
 # username/password
 my $st = Astro::SpaceTrack->new(
     pretty              => 1,
 );
 my $rslt = $st->spacetrack( { json => 1 }, 'iridium' );
 $rslt->is_success()
     or die $rslt->status_line();
 open my $fh, '>', 'iridium.json'
     or die "Failed to open file: $!";
 print { $fh } $rslt->content();
 close $fh;

The following is the equivalent example using the F<SpaceTrack> script:

 SpaceTrack> set pretty 1
 SpaceTrack> spacetrack -json iridium >iridium.json

This method reads the file to be updated, determines the highest C<FILE>
value, and then requests the given OIDs, restricting the return to
C<FILE> values greater than the highest found. If anything is returned,
the file is rewritten.

The following options may be specified:

 -json
   specifies the TLE be returned in JSON format

Options may be specified either in command-line style (that is, as
C<< spacetrack( '-json', ... ) >>) or as a hash reference (that is, as
C<< spacetrack( { json => 1 }, ... ) >>).

B<Note> that there is no way to specify the C<-rcs> or C<-effective>
options. If the file being updated contains these values, they will be
lost as the individual OIDs are updated.

=cut

{

    my %encode = (
	'3le'	=> sub {
	    my ( undef, $data ) = @_;	# JSON object unused
	    return join '', map {
		"$_->{OBJECT_NAME}\n$_->{TLE_LINE1}\n$_->{TLE_LINE2}\n"

t/data/Mock-LWP-UserAgent/resp.json  view on Meta::CPAN

{
   "https://celestrak.org/" : {
      "GET" : [
         "200",
         "OK",
         [
            "Content-Type",
            "text/html; charset=UTF-8"
         ],
         "<!DOCTYPE html>\r\n\r\n<html>\r\n\r\n<head>\r\n\r\n<title>CelesTrak</title>\r\n\r\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/site.css\">\r\n\r\n</head>\r\n\r\n<body>\r\n\r\n<!-- Formerly Celestial BBS and Celestial WWW -->\r\n\r\n<...
      ]
   },
   "https://celestrak.org/NORAD/elements/stations.txt" : {
      "GET" : [
         "200",
         "OK",
         [
            "Content-Type",
            "text/plain"
         ],



( run in 0.244 second using v1.01-cache-2.11-cpan-05444aca049 )