Skip to content

Instantly share code, notes, and snippets.

@gslin
Last active August 29, 2015 14:01
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gslin/cfc326728c1d4e73589e to your computer and use it in GitHub Desktop.
Save gslin/cfc326728c1d4e73589e to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Carp;
use IO::File;
use JSON;
use WWW::Mechanize;
use constant SMOOTH_NUM => 10;
INIT {
croak if !defined $ARGV[0];
my $num = hex $ARGV[0];
my $data = {
jsonrpc => '2.0',
method => 'Aircraft.doGetPlaybackSingle',
params => [$num],
id => 1,
};
my $ua = WWW::Mechanize->new;
my $res = $ua->post('http://api.fr24.com/api/common/v1/json-rpc/', Content => encode_json $data);
croak unless $res->is_success;
my $o = decode_json $res->decoded_content;
say '<?xml version="1.0" encoding="UTF-8"?>';
say '<gpx>';
say '<trk>';
say '<name>fr24-to-gpx</name>';
say '<desc>fr24-to-gpx</desc>';
say '<trkseg>';
my ($last0, $last1);
foreach my $entry (@{$o->{result}->{data}->{track}}) {
if (defined $last0) {
for (my $i = 1; $i < SMOOTH_NUM; $i++) {
printf '<trkpt lat="%s" lon="%s"></trkpt>',
($entry->[0] * $i + $last0 * (SMOOTH_NUM - $i)) / SMOOTH_NUM,
($entry->[1] * $i + $last1 * (SMOOTH_NUM - $i)) / SMOOTH_NUM;
say '';
}
}
printf '<trkpt lat="%s" lon="%s"></trkpt>', $entry->[0], $entry->[1];
say '';
($last0, $last1) = ($entry->[0], $entry->[1]);
}
say '</trkseg>';
say '</trk>';
say '</gpx>';
}
__END__
@gslin
Copy link
Author

gslin commented May 27, 2014

可以用:

curl -X POST -d '{"jsonrpc":"2.0","method":"Aircraft.doGetPlaybackSingle","params":[57241146],"id":1}' http://api.fr24.com/api/common/v1/json-rpc/

取得對應的記錄,其中 57241146 是 365b5d5 (# 後面的 hex 值) 的十進位。

@gslin
Copy link
Author

gslin commented May 28, 2014

這個版本只要提供 365b5d5 就可以了,會自己去抓...

@JennyChang
Copy link

國內線不能Q_Q

@wjtvbm
Copy link

wjtvbm commented Nov 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment