From vk4tec@tech-software.net Thu Jan 30 01:50:58 2014 From: Andrew Rich To: amsat-bb@amsat.org Subject: [amsat-bb] Re: perl script to manipulate keps Date: Thu, 30 Jan 2014 19:50:49 +1000 Message-ID: <137E09B9A5F64A8EBA895389FA0656A5@home30af03032d> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8070727539880440384==" --===============8070727539880440384== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Slight mod=20 system("wget http://www.celestrak.com/NORAD/elements/amateur.txt -O /maint/sc= ripts/keps/amateur.txt"); system("wget http://www.celestrak.com/NORAD/elements/cubesat.txt -O /maint/sc= ripts/keps/cubesat.txt"); system("wget http://www.celestrak.com/NORAD/elements/weather.txt -O /maint/sc= ripts/keps/weather.txt"); ----- Original Message -----=20 From: Andrew Rich=20 To: amsat-bb(a)AMSAT.Org=20 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 () { if (m/VO-52/) { print outfile $_; $next_line =3D ; print outfile $next_line; $next_line =3D ; print outfile $next_line; } } close (outfile); --===============8070727539880440384==-- From gus@8p6sm.net Thu Jan 30 08:00:30 2014 From: Gus To: amsat-bb@amsat.org Subject: [amsat-bb] Re: perl script to manipulate keps Date: Thu, 30 Jan 2014 12:03:54 -0400 Message-ID: <52EA77EA.4050007@8p6sm.net> In-Reply-To: <137E09B9A5F64A8EBA895389FA0656A5@home30af03032d> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3862263961771940657==" --===============3862263961771940657== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This is what I use: ---------------8<------------------ #!/usr/bin/perl -w use FileHandle; use LWP::Simple; @keps_wanted =3D qw( amateur.txt cubesat.txt weather.txt ); $keps_source =3D "http://www.celestrak.com/NORAD/elements"; $keps_local =3D "$ENV{HOME}/keps"; @sats =3D qw( VO-52 AO-7 AO-73); $verbose =3D 1; # set to 0 to eliminate chatter @interesting =3D (); foreach $file (@keps_wanted) { @keps =3D fetch_keps( "$keps_source/$file" ); next unless scalar(@keps); save_file( "$keps_local/$file", @keps ); foreach $sat (@sats) { for ($i=3D0; $i<=3D$#keps; $i++) { $keps[$i] =3D~ /\b$sat\b/ && do { ($name, $line1, $line2) =3D 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 =3D shift; my $txt =3D get( $url ); ! defined $txt && do { print STDERR "Can't retrieve \"$url\"\n"; return undef; }; $txt =3D~ /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 =3D shift; my $out =3D 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) =3D @_; # 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=20 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: amsat-bb(a)AMSAT.Org > 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.t= xt"); > 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 =3D <keps>; > print outfile $next_line; > $next_line =3D <keps>; > print outfile $next_line; > } > } > close (outfile); > > _______________________________________________ > Sent via AMSAT-BB(a)amsat.org. 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 > > --=20 Gus 8P6SM The Easternmost Isle --===============3862263961771940657==-- From vk4tec@tech-software.net Thu Jan 30 12:59:01 2014 From: Andrew Rich <vk4tec@tech-software.net> To: amsat-bb@amsat.org Subject: [amsat-bb] Re: perl script to manipulate keps Date: Fri, 31 Jan 2014 06:58:52 +1000 Message-ID: <76A05F03-FE48-4989-BFB4-B1B5AA042C7A@tech-software.net> In-Reply-To: <52EA77EA.4050007@8p6sm.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6746576823060087127==" --===============6746576823060087127== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Very good=20 Well done Sent from my iPhone > On 31 Jan 2014, at 2:03 am, Gus <gus(a)8p6sm.net> wrote: >=20 > This is what I use: >=20 > ---------------8<------------------ > #!/usr/bin/perl -w >=20 > use FileHandle; > use LWP::Simple; >=20 > @keps_wanted =3D qw( amateur.txt cubesat.txt weather.txt ); > $keps_source =3D "http://www.celestrak.com/NORAD/elements"; > $keps_local =3D "$ENV{HOME}/keps"; >=20 > @sats =3D qw( VO-52 AO-7 AO-73); >=20 >=20 > $verbose =3D 1; # set to 0 to eliminate chatter >=20 > @interesting =3D (); >=20 > foreach $file (@keps_wanted) { > @keps =3D fetch_keps( "$keps_source/$file" ); > next unless scalar(@keps); >=20 > save_file( "$keps_local/$file", @keps ); >=20 > foreach $sat (@sats) { > for ($i=3D0; $i<=3D$#keps; $i++) { > $keps[$i] =3D~ /\b$sat\b/ && do { > ($name, $line1, $line2) =3D cleanup_elements( @keps[$i..$i+2] ); > $verbose && print "$name\n$line1\n$line2\n\n"; > } > }; > } >=20 > #save interesting elements > save_file( "$keps_local/interesting.txt", @interesting ); > } # we're done >=20 > #---------------------------------------------------------# > # read keps directly, no need for wget or other externals # > #---------------------------------------------------------# > sub fetch_keps { > my $url =3D shift; > my $txt =3D get( $url ); >=20 > ! defined $txt && do { > print STDERR "Can't retrieve \"$url\"\n"; > return undef; > }; >=20 > $txt =3D~ /<title>Untitled Document<\/title>/m && do { > print STDERR "No such file: \"$url\"\n"; > return undef; > }; >=20 > $verbose && print "Got \"$url\" OK!\n"; > return split /\n/, $txt; > } >=20 > #--------------------------------------------------# > # write array to file -- first element is filename # > #--------------------------------------------------# > sub save_file { > my $where =3D shift; > my $out =3D new FileHandle "> $where"; > if (! defined $out) { > print STDERR "Can't open \"$where\" for output\n"; > return; > } >=20 > foreach (@_) { > $out->print( "$_\n" ); > } > $out->close(); > } >=20 > #-------------------------------------------------------# > # 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) =3D @_; >=20 > # make corrections here >=20 > push @interesting, ($name, $line1, $line2); >=20 > return ($name, $line1, $line2); > } >=20 > --------------->8------------------ >=20 > Somewhat more verbose, but it doesn't use the external utilities so it is m= ore OS agnostic. >=20 > I keep meaning to expand that final function.... >=20 >=20 >=20 >> On 01/30/2014 05:50 AM, Andrew Rich wrote: >> Slight mod >>=20 >> 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: amsat-bb(a)AMSAT.Org >> Sent: Thursday, January 30, 2014 7:35 PM >> Subject: perl script to manipulate keps >>=20 >>=20 >> Enjoy - just keep adding subs for each bird >>=20 >> #!/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.t= xt"); >> 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 =3D <keps>; >> print outfile $next_line; >> $next_line =3D <keps>; >> print outfile $next_line; >> } >> } >> close (outfile); >>=20 >> _______________________________________________ >> Sent via AMSAT-BB(a)amsat.org. 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 >=20 > --=20 > Gus 8P6SM > The Easternmost Isle > _______________________________________________ > Sent via AMSAT-BB(a)amsat.org. 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 --===============6746576823060087127==--