Very good Well done
Sent from my iPhone > On 31 Jan 2014, at 2:03 am, Gus <[email protected]> wrote: > > This is what I use: > > ---------------8<------------------ > #!/usr/bin/perl -w > > use FileHandle; > use LWP::Simple; > > @keps_wanted = qw( amateur.txt cubesat.txt weather.txt ); > $keps_source = "http://www.celestrak.com/NORAD/elements"; > $keps_local = "$ENV{HOME}/keps"; > > @sats = qw( VO-52 AO-7 AO-73); > > > $verbose = 1; # set to 0 to eliminate chatter > > @interesting = (); > > foreach $file (@keps_wanted) { > @keps = fetch_keps( "$keps_source/$file" ); > next unless scalar(@keps); > > save_file( "$keps_local/$file", @keps ); > > foreach $sat (@sats) { > for ($i=0; $i<=$#keps; $i++) { > $keps[$i] =~ /\b$sat\b/ && do { > ($name, $line1, $line2) = cleanup_elements( @keps[$i..$i+2] ); > $verbose && print "$name\n$line1\n$line2\n\n"; > } > }; > } > > #save interesting elements > save_file( "$keps_local/interesting.txt", @interesting ); > } # we're done > > #---------------------------------------------------------# > # read keps directly, no need for wget or other externals # > #---------------------------------------------------------# > sub fetch_keps { > my $url = shift; > my $txt = get( $url ); > > ! defined $txt && do { > print STDERR "Can't retrieve \"$url\"\n"; > return undef; > }; > > $txt =~ /<title>Untitled Document<\/title>/m && do { > print STDERR "No such file: \"$url\"\n"; > return undef; > }; > > $verbose && print "Got \"$url\" OK!\n"; > return split /\n/, $txt; > } > > #--------------------------------------------------# > # write array to file -- first element is filename # > #--------------------------------------------------# > sub save_file { > my $where = shift; > my $out = new FileHandle "> $where"; > if (! defined $out) { > print STDERR "Can't open \"$where\" for output\n"; > return; > } > > foreach (@_) { > $out->print( "$_\n" ); > } > $out->close(); > } > > #-------------------------------------------------------# > # cleans up elements. currently collects elements for # > # sats of interest, but could also fix checksums, look # > # for duplicates, etc, etc # > #-------------------------------------------------------# > sub cleanup_elements { > my ($name, $line1, $line2) = @_; > > # make corrections here > > push @interesting, ($name, $line1, $line2); > > return ($name, $line1, $line2); > } > > --------------->8------------------ > > Somewhat more verbose, but it doesn't use the external utilities so it is > more OS agnostic. > > I keep meaning to expand that final function.... > > > >> On 01/30/2014 05:50 AM, Andrew Rich wrote: >> Slight mod >> >> system("wget http://www.celestrak.com/NORAD/elements/amateur.txt -O >> /maint/scripts/keps/amateur.txt"); >> system("wget http://www.celestrak.com/NORAD/elements/cubesat.txt -O >> /maint/scripts/keps/cubesat.txt"); >> system("wget http://www.celestrak.com/NORAD/elements/weather.txt -O >> /maint/scripts/keps/weather.txt"); >> ----- Original Message ----- >> From: Andrew Rich >> To: [email protected] >> Sent: Thursday, January 30, 2014 7:35 PM >> Subject: perl script to manipulate keps >> >> >> Enjoy - just keep adding subs for each bird >> >> #!/usr/bin/perl >> system("rm /maint/scripts/keps/*.txt"); >> system("wget http://www.celestrak.com/NORAD/elements/amateur.txt"); >> system("wget http://www.celestrak.com/NORAD/elements/cubesat.txt"); >> system("wget http://www.celestrak.com/NORAD/elements/weather.txt"); >> system("cat /maint/scripts/keps/*.txt > >> /maint/scripts/keps/total_keps.txt"); >> open (outfile,"> /maint/scripts/keps/final_keps.txt"); >> open (keps,"/maint/scripts/keps/total_keps.txt"); >> while (<keps>) >> { >> if (m/VO-52/) >> { >> print outfile $_; >> $next_line = <keps>; >> print outfile $next_line; >> $next_line = <keps>; >> print outfile $next_line; >> } >> } >> close (outfile); >> >> _______________________________________________ >> Sent via [email protected]. Opinions expressed are those of the author. >> Not an AMSAT-NA member? Join now to support the amateur satellite program! >> Subscription settings: http://amsat.org/mailman/listinfo/amsat-bb > > -- > Gus 8P6SM > The Easternmost Isle > _______________________________________________ > Sent via [email protected]. Opinions expressed are those of the author. > Not an AMSAT-NA member? Join now to support the amateur satellite program! > Subscription settings: http://amsat.org/mailman/listinfo/amsat-bb _______________________________________________ Sent via [email protected]. Opinions expressed are those of the author. Not an AMSAT-NA member? Join now to support the amateur satellite program! Subscription settings: http://amsat.org/mailman/listinfo/amsat-bb
