This is a rework of an older script I made which did the same, but was really nasty and I doubt that this is any better *grin* Anyways it grabs the current APOD and outputs it to the cwd of where you called the script. It dates the output file as: apod(yyyy)(mm)(dd), where yyyy,mm,dd is the month day year respectively, and no the parenthesis aren't in the filename.
Edit: Changed the date format from month,day,year to year,month,day to make sorting alot easier. Pointed out by sauoq
Edit2: Updated URI, added png.
#!/usr/bin/perl
use strict;
use warnings;
use URI::URL;
use LWP::Simple qw/get/;
my $TOP = "http://apod.nasa.gov/apod/";
my $IMGPATH = 'image/\d{4}/\w+.(gif|jpg|jpeg|png)';
my @timearray = gmtime();
my $time = sprintf "%04d%02d%02d", ($timearray[5]+1900), ($timearray[4
+]+1), ($timearray[3]);
my $content = get $TOP or die "Cannot get APOD Page\n";
my ($imgurl) = $content =~ m!($IMGPATH)!i;
$imgurl = url($imgurl,$TOP)->abs;
my $picture = get $imgurl or die "Cannot grab image: $!\n";
open(OUT, ">apod$time\.$2") or die "Cannot write to file: $!\n";
binmode(OUT);
print OUT $picture;
close OUT;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|