lib/OpenSky/API.pm

filter: Statementstmt 31.0% 36 / 116 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 54.5% 12 / 22 Podpod n/a totaltotal 22.4% 48 / 214 CC 35 SCAR 33.1
CC
35
Cov
20%
_get_response
56.0
get_states
42.0
_url
42.0
CRAP 27.4
↑ Summary blib/lib/OpenSky/API.pm »
1 # see also https://github.com/openskynetwork/opensky-api
2  
3 package OpenSky::API;
4  
5 # ABSTRACT: Perl interface to the OpenSky Network API
6  
7 our $VERSION = '0.002';
8 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 use OpenSky::API::Types qw(
10 ArrayRef
11 Bool
12 Dict
13 HashRef
14 InstanceOf
15 Int
16 Latitude
17 Longitude
18 NonEmptyStr
19 Num
20 Optional
21 5 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use OpenSky::API::States;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use OpenSky::API::Flights;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use PerlX::Maybe;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use Config::INI::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 5 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use Mojo::JSON qw( decode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use Type::Params -sigs;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 has config => (
35 is => 'ro',
36 isa => NonEmptyStr,
37 default => sub ($self) { $ENV{HOME} . '/.openskyrc' },
38 );
39  
40 has [qw/debug raw testing/] => (
41 is => 'ro',
42 isa => Bool,
43 default => 0,
44 );
45  
46 has _config_data => (
47 is => 'ro',
48 isa => HashRef,
49 init_arg => undef,
50 lazy => 1,
51 default => sub ($self) {
52 Config::INI::Reader->read_file( $self->config );
53 },
54 );
55  
56 has _ua => (
57 is => 'ro',
58 isa => InstanceOf ['Mojo::UserAgent'],
59 init_arg => undef,
60 default => sub { Mojo::UserAgent->new },
61 );
62  
63 has _username => (
64 is => 'ro',
65 isa => NonEmptyStr,
66 lazy => 1,
67 init_arg => 'username',
68 default => sub ($self) { $ENV{OPENSKY_USERNAME} // $self->_config_data->{opensky}{username} },
69 );
70  
71 has _password => (
72 is => 'ro',
73 isa => NonEmptyStr,
74 lazy => 1,
75 init_arg => 'password',
76 default => sub ($self) { $ENV{OPENSKY_PASSWORD} // $self->_config_data->{opensky}{password} },
77 );
78  
79 has _base_url => (
80 is => 'ro',
81 init_arg => 'base_url',
82 isa => NonEmptyStr,
83 default => sub ($self) {'https://opensky-network.org/api'},
84 );
85  
86 has limit_remaining => (
87 is => 'ro',
88 isa => Int,
89 lazy => 1,
90 writer => '_set_limit_remaining',
91 default => sub ($self) {
92 return 4000 if $self->testing;
93  
94 # per their documentation,
95 # https://openskynetwork.github.io/opensky-api/rest.html#api-credit-usage,
96 # this request should only cost one credit. However, it appears to
97 # cost three.
98 my %params = (
99 lamin => 49.7,
100 lomin => 3.2,
101 lamax => 50.5,
102 lomax => 4.6,
103 );
104 my $route = '/states/all';
105 return $self->_get_response( route => $route, params => \%params, credits => 1 );
106 },
107 );
108  
109 signature_for get_states => (
110 method => 1,
111 named => [
112 time => Optional [Num], { default => 0 },
113 icao24 => Optional [ NonEmptyStr | ArrayRef [NonEmptyStr] ],
114 bbox => Optional [
115 Dict [
116 lamin => Latitude,
117 lomin => Longitude,
118 lamax => Latitude,
119 lomax => Longitude,
120 ],
121 { default => {} },
122 ],
123 extended => Optional [Bool],
124 ],
125 named_to_list => 1,
126 );
127  
128 ▶sub get_states ( $self, $seconds, $icao24, $bbox, $extended ) {
Subroutine get_states: not called CC=6 SCAR=37.4
129 0 my %params = (
130 maybe time => $seconds,
131 maybe icao24 => $icao24,
132 maybe extended => $extended,
133 );
134 0 ▶ if ( keys $bbox->%* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$bbox) 0 0 0
135 0 $params{$_} = $bbox->{$_} for qw( lamin lomin lamax lomax );
136 }
137  
138 0 my $route = '/states/all';
139 0 ▶ my $response = $self->_get_response( route => $route, params => \%params, no_auth_required => 1 ) // {
Condition0%0/4
$self->_get_response("route", $route, "params", \%params, "no_auth_required", 1) // {"time", time - ($seconds // 0), "states", []}
l!l
00
$seconds // 0
l!l
00
MC/DC0%0/1
$self->_get_response("route", $route, "params", \%params, "no_auth_required", 1) // {"time", time - ($seconds // 0), "states", []}
$self->_get_response("route", $route, "params", \%params, "no_auth_required", 1)
MC/DC0%0/1
$seconds // 0
$seconds
Truth table0%0/2
A
A= $self->_get_response("route", $route, "params", \%params, "no_auth_required", 1)
Aresult
11
00
Truth table0%0/2
A
A= $seconds
Aresult
11
00
140 time => time - ( $seconds // 0 ),
141 states => [],
142 };
143 0 ▶ if ( $self->raw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raw) 0 0 0
144 0 return $response;
145 }
146 0 return OpenSky::API::States->new($response);
147 }
148  
149 signature_for get_my_states => (
150 method => 1,
151 named => [
152 time => Optional [Num], { default => 0 },
153 icao24 => Optional [ NonEmptyStr | ArrayRef [NonEmptyStr] ],
154 serials => Optional [ NonEmptyStr | ArrayRef [NonEmptyStr] ],
155 ],
156 named_to_list => 1,
157 );
158  
159 ▶sub get_my_states ( $self, $seconds, $icao24, $serials ) {
Subroutine get_my_states: not called CC=2 SCAR=17.9
160 0 my %params = (
161 extended => 1,
162 maybe time => $seconds,
163 maybe icao24 => $icao24,
164 maybe serials => $serials,
165 );
166  
167 0 my $route = '/states/own';
168 0 my $response = $self->_get_response( route => $route, params => \%params );
169 0 ▶ if ( $self->raw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raw) 0 0 0
170 0 return $response;
171 }
172 0 return OpenSky::API::States->new($response);
173 }
174  
175 ▶sub get_flights_from_interval ( $self, $begin, $end ) {
Subroutine get_flights_from_interval: not called CC=5 SCAR=34.0
176 0 ▶ if ( $begin >= $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin >= $end) 0 0 0
177 0 croak 'The end time must be greater than or equal to the start time.';
178 }
179 0 ▶ if ( ( $end - $begin ) > 7200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end - $begin > 7200) 0 0 0
180 0 croak 'The time interval must be smaller than two hours.';
181 }
182  
183 0 my %params = ( begin => $begin, end => $end );
184 0 my $route = '/flights/all';
185 0 ▶ my $response = $self->_get_response( route => $route, params => \%params ) // [];
Condition0%0/2
$self->_get_response("route", $route, "params", \%params) // []
l!l
00
MC/DC0%0/1
$self->_get_response("route", $route, "params", \%params) // []
$self->_get_response("route", $route, "params", \%params)
Truth table0%0/2
A
A= $self->_get_response("route", $route, "params", \%params)
Aresult
11
00
186  
187 0 ▶ if ( $self->raw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raw) 0 0 0
188 0 return $response;
189 }
190 0 return OpenSky::API::Flights->new($response);
191 }
192  
193 ▶sub get_flights_by_aircraft ( $self, $icao24, $begin, $end ) {
Subroutine get_flights_by_aircraft: not called CC=5 SCAR=34.0
194 0 ▶ if ( $begin >= $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin >= $end) 0 0 0
195 0 croak 'The end time must be greater than or equal to the start time.';
196 }
197 0 ▶ if ( ( $end - $begin ) > 2592 * 1e3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end - $begin > 2592000) 0 0 0
198 0 croak 'The time interval must be smaller than 30 days.';
199 }
200  
201 0 my %params = ( icao24 => $icao24, begin => $begin, end => $end );
202 0 my $route = '/flights/aircraft';
203 0 ▶ my $response = $self->_get_response( route => $route, params => \%params ) // [];
Condition0%0/2
$self->_get_response("route", $route, "params", \%params) // []
l!l
00
MC/DC0%0/1
$self->_get_response("route", $route, "params", \%params) // []
$self->_get_response("route", $route, "params", \%params)
Truth table0%0/2
A
A= $self->_get_response("route", $route, "params", \%params)
Aresult
11
00
204  
205 0 ▶ if ( $self->raw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raw) 0 0 0
206 0 return $response;
207 }
208 0 return OpenSky::API::Flights->new($response);
209 }
210  
211 ▶sub get_arrivals_by_airport ( $self, $airport, $begin, $end ) {
Subroutine get_arrivals_by_airport: not called CC=5 SCAR=34.0
212 0 ▶ if ( $begin >= $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin >= $end) 0 0 0
213 0 croak 'The end time must be greater than or equal to the start time.';
214 }
215 0 ▶ if ( ( $end - $begin ) > 604800 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end - $begin > 604800) 0 0 0
216 0 croak 'The time interval must be smaller than 7 days.';
217 }
218  
219 0 my %params = ( airport => $airport, begin => $begin, end => $end );
220 0 my $route = '/flights/arrival';
221 0 ▶ my $response = $self->_get_response( route => $route, params => \%params ) // [];
Condition0%0/2
$self->_get_response("route", $route, "params", \%params) // []
l!l
00
MC/DC0%0/1
$self->_get_response("route", $route, "params", \%params) // []
$self->_get_response("route", $route, "params", \%params)
Truth table0%0/2
A
A= $self->_get_response("route", $route, "params", \%params)
Aresult
11
00
222  
223 0 ▶ if ( $self->raw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raw) 0 0 0
224 0 return $response;
225 }
226 0 return OpenSky::API::Flights->new($response);
227 }
228  
229 ▶sub get_departures_by_airport ( $self, $airport, $begin, $end ) {
Subroutine get_departures_by_airport: not called CC=5 SCAR=34.0
230 0 ▶ if ( $begin >= $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin >= $end) 0 0 0
231 0 croak 'The end time must be greater than or equal to the start time.';
232 }
233 0 ▶ if ( ( $end - $begin ) > 604800 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end - $begin > 604800) 0 0 0
234 0 croak 'The time interval must be smaller than 7 days.';
235 }
236  
237 0 my %params = ( airport => $airport, begin => $begin, end => $end );
238 0 my $route = '/flights/departure';
239 0 ▶ my $response = $self->_get_response( route => $route, params => \%params ) // [];
Condition0%0/2
$self->_get_response("route", $route, "params", \%params) // []
l!l
00
MC/DC0%0/1
$self->_get_response("route", $route, "params", \%params) // []
$self->_get_response("route", $route, "params", \%params)
Truth table0%0/2
A
A= $self->_get_response("route", $route, "params", \%params)
Aresult
11
00
240  
241 0 ▶ if ( $self->raw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raw) 0 0 0
242 0 return $response;
243 }
244 0 return OpenSky::API::Flights->new($response);
245 }
246  
247 signature_for _get_response => (
248 method => 1,
249 named => [
250 route => NonEmptyStr,
251 params => Optional [HashRef],
252 credits => Optional [Bool],
253 no_auth_required => Optional [Bool],
254 ],
255 named_to_list => 1,
256 );
257  
258 ▶sub _get_response ( $self, $route, $params, $credits, $no_auth_required ) {
Subroutine _get_response: not called CC=7 SCAR=40.3
259 0 my $url = $self->_url( $route, $params, $no_auth_required );
260  
261 0 my $response = $self->_GET($url);
262 0 my $remaining = $response->headers->header('X-Rate-Limit-Remaining');
263  
264 0 $self->_debug( $response->headers->to_string . "\n" );
265  
266 # not all requests cost credits, so we only want to set the limit if
267 # $remaining is defined
268 0 ▶ $self->_set_limit_remaining($remaining) if !$credits && defined $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if not $credits and defined $remaining 0 0 0
Condition0%0/3
not $credits and defined $remaining
!ll&&!rl&&r
000
MC/DC0%0/2
not $credits and defined $remaining
not $credits defined $remaining
Truth table0%0/3
not(A) and B
A= not $creditsB= defined $remaining
ABresult
0X0
100
111
269 0 ▶ if ( !$response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
270 0 ▶ if ( $response->code == 404 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->code == 404) 0 0 0
271  
272 # this is annoying. If the didn't match any criteria, return a 200
273 # and and empty element. Instead, we get a 404.
274 0 return;
275 }
276 0 croak $response->to_string;
277 }
278 0 ▶ return $remaining if $credits;
Branch: 1 branch
BranchTrueFalseTotal
if $credits 0 0 0
279 0 ▶ if ( $self->debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
280 0 $self->_debug( $response->body );
281 }
282 0 return decode_json( $response->body );
283 }
284  
285 # an easy target to override for testing
286 ▶sub _GET ( $self, $url ) {
Subroutine _GET: not called CC=1 SCAR=6.9
287 0 $self->_debug("GET $url\n");
288 0 return $self->_ua->get($url)->res;
289 }
290  
291 ▶sub _debug ( $self, $msg ) {
Subroutine _debug: not called CC=2 SCAR=17.9
292 0 ▶ return if !$self->debug;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->debug 0 0 0
293 0 say STDERR $msg;
294 }
295  
296 0 ▶sub _url ( $self, $url, $params = {}, $no_auth_required = 0 ) {
Subroutine _url: not called CC=6 SCAR=37.4
297 0 my $username = $self->_username;
298 0 my $password = $self->_password;
299 0 ▶ if ( ( !$username || !$password ) && $no_auth_required ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $username && $password and $no_auth_required) 0 0 0
Condition0%0/6
not $username && $password and $no_auth_required
!ll&&!rl&&r
000
$username && $password
!ll&&!rl&&r
000
MC/DC0%0/3
not $username && $password and $no_auth_required
$username $password $no_auth_required
Truth table0%0/5
not(A && B) and C
A= $usernameB= $passwordC= $no_auth_required
ABCresult
11X0
0X00
1000
0X11
1011
300 0 return Mojo::URL->new( $self->_base_url . $url )->query($params);
301 }
302 0 $url = Mojo::URL->new( $self->_base_url . $url )->userinfo( $self->_username . ':' . $self->_password );
303 0 $url->query($params);
304 0 return $url;
305 }
306  
307 __PACKAGE__->meta->make_immutable;
308  
309 __END__
310  
311 =pod
312  
313 =encoding UTF-8
314  
315 =head1 NAME
316  
317 OpenSky::API - Perl interface to the OpenSky Network API
318  
319 =head1 VERSION
320  
321 version 0.002
322  
323 =head1 SYNOPSIS
324  
325 use OpenSky::API;
326  
327 my $api = OpenSky::API->new(
328 username => 'username',
329 password => 'password',
330 );
331  
332 my $states = $api->get_states;
333 while ( my $vector = $states->next ) {
334 say $vector->callsign;
335 }
336  
337 =head1 DESCRIPTION
338  
339 This is a Perl interface to the OpenSky Network API. It provides a simple, object-oriented
340 interface, but also allows you to fetch raw results for performance.
341  
342 This is largely based on L<the official Python
343 implementation|https://github.com/openskynetwork/opensky-api/blob/master/python/opensky_api.py>,
344 but with some changes to make it more user-friendly for Perl developers.
345  
346 =head1 CONSTRUCTOR
347  
348 Basic usage:
349  
350 my $open_sky = OpenSky::API->new;
351  
352 This will create an instance of the API object with no authentication. This only allows you access
353 to the C<get_states> method.
354  
355 If you want to use the other methods, you will need to provide a username and password:
356  
357 my $open_sky = OpenSky::API->new(
358 username => 'username',
359 password => 'password',
360 );
361  
362 Alterantively, you can set the C<OPENSKY_USERNAME> and C<OPENSKY_PASSWORD>
363 environment variables, or create a C<.openskyrc> file in your home directory
364 with the following contents:
365  
366 [opensky]
367 username = myusername
368 password = s3cr3t
369  
370 By default, all methods return objects. If you want to get the raw results, you can set the C<raw>
371 attribute in the constructor:
372  
373 my $open_sky = OpenSky::API->new(
374 raw => 1,
375 );
376  
377 If you are debugging why something failed, pass the C<debug> attribute:
378  
379 my $open_sky = OpenSky::API->new(
380 debug => 1,
381 );
382  
383 =head1 METHODS
384  
385 For more insight to all methods, see L<the OpenSky API
386 documentation|https://openskynetwork.github.io/opensky-api/>.
387  
388 =head2 get_states
389  
390 my $states = $api->get_states;
391  
392 Returns an instance of L<OpenSky::API::States>. if C<< raw => 1 >> was passed
393 to the constructor, this will be the raw data structure instead.
394  
395 This API call can be used to retrieve any state vector of the
396 OpenSky. Please note that rate limits apply for this call. For API calls
397 without rate limitation, see C<get_my_states>.
398  
399 By default, the above fetches all current state vectors.
400  
401 You can (optionally) request state vectors for particular airplanes or times using the following request parameters:
402  
403 my $states = $api->get_states(
404 icao24 => 'abc9f3',
405 time => 1517258400,
406 );
407  
408 Both parameters are optional.
409  
410 =over 4
411  
412 =item * C<icao24>
413  
414 One or more ICAO24 transponder addresses represented by a hex string (e.g. abc9f3). To filter multiple ICAO24 append the property once for each address. If omitted, the state vectors of all aircraft are returned.
415  
416 =item * C<time>
417  
418 A Unix timestamp (seconds since epoch). Only state vectors after this timestamp are returned.
419  
420 =back
421  
422 In addition to that, it is possible to query a certain area defined by a
423 bounding box of WGS84 coordinates. For this purpose, add the following
424 parameters:
425  
426 my $states = $api->get_states(
427 bbox => {
428 lomin => -0.5, # lower bound for the longitude in decimal degrees
429 lamin => 51.25, # lower bound for the latitude in decimal degrees
430 lomax => 0, # upper bound for the longitude in decimal degrees
431 lamax => 51.75, # upper bound for the latitude in decimal degrees
432 },
433 );
434  
435 You can also request the category of aircraft by adding the following request parameter:
436  
437 my $states = $api->get_states(
438 extended => 1,
439 );
440  
441 Any and all of the above parameters can be combined.
442  
443 my $states = $api->get_states(
444 icao24 => 'abc9f3',
445 time => 1517258400,
446 bbox => {
447 lomin => -0.5, # lower bound for the longitude in decimal degrees
448 lamin => 51.25, # lower bound for the latitude in decimal degrees
449 lomax => 0, # upper bound for the longitude in decimal degrees
450 lamax => 51.75, # upper bound for the latitude in decimal degrees
451 },
452 extended => 1,
453 );
454  
455 =head2 get_my_states
456  
457 my $states = $api->get_my_states;
458  
459 Returns an instance of L<OpenSky::API::States>. if C<< raw => 1 >> was passed,
460 this will be the raw data structure instead.
461  
462 This API call can be used to retrieve state vectors for your own
463 sensors without rate limitations. Note that authentication is required for
464 this operation, otherwise you will get a 403 - Forbidden.
465  
466 By default, the above fetches all current state vectors for your states. However, you can also pass
467 arguments to fine-tune this:
468  
469 my $states = $api->get_my_states(
470 time => 1517258400,
471 icao24 => 'abc9f3',
472 serials => [ 1234, 5678 ],
473 );
474  
475 =over 4
476  
477 =item * C<time>
478  
479 The time in seconds since epoch (Unix timestamp to retrieve states for. Current time will be used if omitted.
480  
481 =item * <icao24>
482  
483 One or more ICAO24 transponder addresses represented by a hex string (e.g.
484 abc9f3). To filter multiple ICAO24 append the property once for each address.
485 If omitted, the state vectors of all aircraft are returned.
486  
487 =item * C<serials>
488  
489 Retrieve only states of a subset of your receivers. You can pass this argument
490 several time to filter state of more than one of your receivers. In this case,
491 the API returns all states of aircraft that are visible to at least one of the
492 given receivers.
493  
494 =back
495  
496 =head2 C<get_arrivals_by_airport>
497  
498 my $arrivals = $api->get_arrivals_by_airport('KJFK', $start, $end);
499  
500 Returns an instance of L<OpenSky::API::Flights>. if C<< raw => 1 >> was
501 passed, you will get the raw data structure instead.
502  
503 Positional arguments:
504  
505 =over 4
506  
507 =item * C<airport>
508  
509 The ICAO code of the airport you want to get arrivals for.
510  
511 =item * C<start>
512  
513 The start time in seconds since epoch (Unix timestamp).
514  
515 =item * C<end>
516  
517 The end time in seconds since epoch (Unix timestamp).
518  
519 =back
520  
521 The interval between start and end time must be smaller than seven days.
522  
523 =head2 C<get_departures_by_airport>
524  
525 Identical to C<get_arrivals_by_airport>, but returns departures instead of arrivals.
526  
527 =head2 C<get_flights_by_aircraft>
528  
529 my $flights = $api->get_flights_by_aircraft('abc9f3', $start, $end);
530  
531 Returns an instance of L<OpenSky::API::Flights>. if C<< raw => 1 >> was passed
532 to the constructor, you will get the raw data structure instead.
533  
534 The first argument is the ICAO24 transponder address of the aircraft you want.
535  
536 =head2 C<get_flights_from_interval>
537  
538 my $flights = $api->get_flights_from_interval($start, $end);
539  
540 Returns an instance of L<OpenSky::API::Flights>. if C<< raw => 1 >> was passed
541 to the constructor, you will get the raw data structure instead.
542  
543 =head1 EXAMPLES
544  
545 Perl Wikipedia, L<OpenSky Network|https://en.wikipedia.org/wiki/OpenSky_Network> is ...
546  
547 The OpenSky Network is a non-profit association based in Switzerland that
548 provides open access of flight tracking control data. It was set up as
549 a research project by several universities and government entities with
550 the goal to improve the security, reliability and efficiency of the
551 airspace. Its main function is to collect, process and store air traffic
552 control data and provide open access to this data to the public. Similar
553 to many existing flight trackers such as Flightradar24 and FlightAware,
554 the OpenSky Network consists of a multitude of sensors (currently around
555 1000, mostly concentrated in Europe and the US), which are connected to
556 the Internet by volunteers, industrial supporters, academic, and
557 governmental organizations. All collected raw data is archived in a
558 large historical database, containing over 23 trillion air traffic control
559 messages (November 2020). The database is primarily used by researchers
560 from different areas to analyze and improve air traffic control
561 technologies and processes
562  
563 =head2 Elon Musk's Jet
564  
565 However, this data can be used to track the movements of certain aircraft. For
566 example, Elon Musk's primary private jet (he has three, but this is the one he
567 mainly uses), has the ICAO24 transponder address C<a835af>. Running the
568 following code ...
569  
570 use OpenSky::API;
571  
572 my $musks_jet = 'a835af';
573 my $openapi = OpenSky::API->new;
574  
575 my $days = 7;
576 my $now = time;
577 my $then = $now - 86400 * 7; # up to 7 days ago
578  
579 my $flight_data = $openapi->get_flights_by_aircraft( $musks_jet, $then, $now );
580 say "Jet $musks_jet has " . $flight_data->count . " flights";
581  
582 As of this writing, that prints out:
583  
584 Jet a835af has 6 flights
585  
586 =head1 ETHICS
587  
588 There are some ethical considerations to be made when using this module. I was
589 ambivalent about writing it, but I decided to do so because I think it's
590 important to be aware of the privacy implications. However, it's also
591 important to be aware of the L<climate
592 implications|https://www.euronews.com/green/2023/03/30/wasteful-luxury-private-jet-pollution-more-than-doubles-in-europe>.
593  
594 Others are using the OpenSky API to model the amount of carbon being released
595 by the aviation industry, while others have used this public data to predict
596 corporate mergers and acquisitions. There are a wealth of reasons why this
597 data is useful, but not all of those reasons are good. Be good.
598  
599 =head1 TODO
600  
601 =over 4
602  
603 =item * Implement rate limits
604  
605 =item * Add a C<is_rate_limited> method to results
606  
607 =item * Add Waypoints and Flight Routes
608  
609 =back
610  
611 =head1 AUTHOR
612  
613 Curtis "Ovid" Poe <curtis.poe@gmail.com>
614  
615 =head1 COPYRIGHT AND LICENSE
616  
617 This software is Copyright (c) 2023 by Curtis "Ovid" Poe.
618  
619 This is free software, licensed under:
620  
621 The Artistic License 2.0 (GPL Compatible)
622  
623 =cut
↑ Summary blib/lib/OpenSky/API.pm »