Friday, August 04, 2006

APOD Viewer v1

I love APOD - Astronomy Picture of the Day - as I'm privately quite interested in the universe and all that stuff. But I do not visit APOD daily, so once in a while I browse the site.

But, wouldn't it be nice to have a slideshow with the pictures?

Surprise! PowerShell to the rescue.

This script really show the power of PowerShell. It has a web client, caculates dates and controls Internet Explorer. Give it a shot. If you make any clever changes, please post those as comments. I have a big wishlist myself, but this got me going.

function apod {
param([int] $days=1) # show latest picture by default

# create IE COM object
$ie = new-object -com internetexplorer.application

# create .net object
$webclient = new-object

# date manipulation
$date.AddDays(1) # start tomorrow as the loops starts by subtracting a day

# You may have to press the window in the taskbar to make it appear

# An easy way to do a for loop - could have used for, but as said this is easier
1..$days | % {

# back one day

# construct url
$url=$baseurl+"ap" + $date.tostring("yyMMdd") + ".html"

# get HTML page
$html = $webclient.downloadstring($url)

# Pick up the link the picture has - links to the high resolution version
# I want to display
# This is not idiot proff coding - but, hey, scripts are easy to change

$html -match '<a href="([^"]*)">\W*<img'
# get the value matching the pattern in parenthesis

# show high resolution picture

# wait for IE to load picture
while ($ie.busy) {sleep -s 1;"busy"}

# give me 10 seconds to enjoy the picture
sleep -s 10


# shutdown IE


# wish list: load pictures overlapping (but keep presentation interval)
# wish list: include some kind of fancy transition
# wish list: pick out the explanation and present it in some way
# add our own...


No comments: