#!/bin/bash

apod_dir=~/img/apod
bg_set_cmd='/usr/bin/feh --bg-scale'
apod_url=http://antwrp.gsfc.nasa.gov/apod
tmp_file=/tmp/apodtmp

wget $apod_url --output-document $tmp_file

# ASSUMPTION: the apod anchor are of form '<a href="image/...">'
# AND it's the only such string
# AND it's on a line by itself
# AND it refers to a relative path from the /apod directory
img_url="`grep 'href="image' $tmp_file`"
img_url=${img_url#<a href=\"} # remove the beginning
img_url=${img_url%\">}        # remove the end

cd $apod_dir
wget $apod_url/$img_url
$bg_set_cmd `basename $img_url`

exit 0

