Last active
August 29, 2015 14:01
-
-
Save gslin/cfc326728c1d4e73589e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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__ |
這個版本只要提供 365b5d5 就可以了,會自己去抓...
國內線不能Q_Q
http://api.fr24.com/api/common/v1/json-rpc
403 - Forbidden....@@"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以用:
取得對應的記錄,其中 57241146 是 365b5d5 (# 後面的 hex 值) 的十進位。