add_new_from_tle_file.pl   add_new_from_tle_file.pl 
#!/usr/bin/perl #!/usr/bin/perl
# This is a helper script of download_tle_find_new.sh
# It accepts a TLE list, checks if the satellites in it already are listed
in
# satellites.json, and if not, outputs appropriately formatted JSON entries
.
# The new satellites are added to the groups passed as parameters.
#my $groups = "\"scientific\", \"weather\", \"non-operational\""; #my $groups = "\"scientific\", \"weather\", \"non-operational\"";
map { s/^/"/; s/$/"/; } @ARGV; map { s/^/"/; s/$/"/; } @ARGV;
my $groups = join(", ", @ARGV); my $groups = join(", ", @ARGV);
my %ignore; my %ignore;
open(SAT, "<satellites.json") || die "cannot open existing satellites.json file"; open(SAT, "<satellites.json") || die "Cannot open existing satellites.json file";
while(<SAT>) { while(<SAT>) {
chomp; chomp;
if (/^\s*\"([^"]+)":\s*$/) { if (/^\s*\"([^"]+)":\s*$/) {
$ignore{$1} = 1; $ignore{$1} = 1;
} }
} }
my(%h); my(%h);
my $count = 0;
while(<STDIN>) { while(<STDIN>) {
chomp; chomp;
s/\s+$//; s/\s+$//;
$_ =~ /^2\s(\d+)\s/; $_ =~ /^2\s(\d+)\s/;
$h{'id'} = $1; $h{'id'} = $1;
if (/^1/) { $h{'tle1'} = $_; } if (/^1/) { $h{'tle1'} = $_; }
elsif (/^2/) { elsif (/^2/) {
$h{'tle2'} = $_; $h{'tle2'} = $_;
out(%h); out(%h);
foreach my $k (keys %h) {delete $h{$k};} foreach my $k (keys %h) {delete $h{$k};}
} }
else { else {
s/\s*\[[^\]]+\]\s*$//; s/\s*\[[^\]]+\]\s*$//;
$h{'name'} = $_; $h{'name'} = $_;
} }
} }
print STDERR "Added " . $count . " new in [" . $groups . "]\n";
sub out { sub out {
if (defined($ignore{$h{'id'}})) { if (defined($ignore{$h{'id'}})) {
print STDERR "ignoring " . $h{'id'} . "\n"; print STDERR "Ignoring " . $h{'id'} . "/" . $h{'name'} . "\n ";
return; return;
} }
printf "\t\t\"%s\":\n", $h{'id'}; printf "\t\t\"%s\":\n", $h{'id'};
print "\t\t{\n"; print "\t\t{\n";
print "\t\t\t\"groups\": [$groups],\n"; print "\t\t\t\"groups\": [$groups],\n";
print "\t\t\t\"orbitVisible\": false,\n"; print "\t\t\t\"orbitVisible\": false,\n";
printf "\t\t\t\"name\": \"%s\",\n", $h{'name'}; printf "\t\t\t\"name\": \"%s\",\n", $h{'name'};
printf "\t\t\t\"tle1\": \"%s\",\n", $h{'tle1'}; printf "\t\t\t\"tle1\": \"%s\",\n", $h{'tle1'};
printf "\t\t\t\"tle2\": \"%s\",\n", $h{'tle2'}; printf "\t\t\t\"tle2\": \"%s\",\n", $h{'tle2'};
print "\t\t\t\"visible\": false\n"; print "\t\t\t\"visible\": false\n";
print "\t\t},\n"; print "\t\t},\n";
$count++;
} }
 End of changes. 6 change blocks. 
2 lines changed or deleted 14 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/