Retrograde Motion

ziggy on 2003-12-17T00:16:30

Today's Astronomy Picture of the Day has an excellent time-lapse photo showing Mars (and, coincidentally, Uranus) in retrograde motion. Neat!


apod

inkdroid on 2003-12-22T18:40:36

I love APOD so much that I wrote a little Perl script a few years ago to download the image and make it my background. The site has stayed remarkably stable, and the script just keeps on working :-) It's funny to look at now, because I would write the program a bit different now...it's a bit of personal Perl arachaeology.
use strict;
use Sys::Hostname;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use File::Copy;

my $DEBUG = 1;

my $backgroundLocation = "/usr/share/pixmaps/backgrounds/dailyAstro.jpg";
my $publicId = "AstroFind/v1.0";
my $baseUrl = "http://antwrp.gsfc.nasa.gov";
my $url = "$baseUrl/apod/astropix.html";

## get the stable HTML page
print "astro: fetching $url\n" if $DEBUG;
my $ua = LWP::UserAgent->new();
$ua->agent($publicId);
my $req = HTTP::Request->new(GET => $url);
$req->referer(Sys::Hostname::hostname());
my $response = $ua->request($req);

## get the image location
my $astroHTML = $response->content();
my ($imgTag) = $astroHTML =~ /<a href="(image.*)">?/mi;
my $imageLocation =  "$baseUrl/$imgTag";

## add on jpg if it doesn't have an extension
if ($imageLocation !~ /\.....?$/) { $imageLocation .= '.jpg'; }

print STDERR "astro: fetching $imageLocation\n" if $DEBUG;

## fetch the image
$req = HTTP::Request->new(GET => $imageLocation);
my $response = $ua->request($req);
my $astroImage = $response->content();

## write the file!
open(IMG,">$backgroundLocation");
print IMG $astroImage;
close(IMG);

if ($response->is_success()) {
    print "astro: got image and wrote to $backgroundLocation\n" if $DEBUG;
}
else {
    print "astro: failed to get image\n";
}