0

Need to download images using range of dates or specified date from Nasa. The date keeps defaulting to current date although I input different date.

TODAY= read -p "Enter date: "$(+%Y-%m-%d)

if [ ! -e ~/Pictures/${TODAY}_apod.jpg ]; then echo "We don't have the    picture saved, save it"

get_page


PICURL=`/bin/cat /tmp/pic_url`

echo  "Picture URL is: ${PICURL}"

echo  "Downloading image"
wget --quiet $PICURL -O $PICTURES_DIR/${TODAY}_apod.jpg

 echo "Setting image as wallpaper"
 gconftool-2 -t string -s /desktop/gnome/background/picture_filename                              $PICTURES_DIR/${TODAY}_apod.jpg

save_description
else get_page

PICURL=`/bin/cat /tmp/pic_url`

echo  "Picture URL is: ${PICURL}"

SITEFILESIZE=$(wget --spider $PICURL 2>&1 | grep Length | awk '{print $2}')
FILEFILESIZE=$(stat -c %s $PICTURES_DIR/${TODAY}_apod.jpg)

if [ $SITEFILESIZE != $FILEFILESIZE ]; then
echo "The picture has been updated, getting updated copy"
rm $PICTURES_DIR/${TODAY}_apod.jpg


PICURL=`/bin/cat /tmp/pic_url`

echo  "Downloading image"
wget --quiet $PICURL -O $PICTURES_DIR/${TODAY}_apod.jpg

echo "Setting image as wallpaper"
$PICTURES_DIR/${TODAY}_apod.jpg

save_description

else echo "Picture is the same, finishing up" fi It should download image from the date provided.

Chili
  • 1
  • 1
  • See: [How do I format my code blocks?](https://stackoverflow.com/questions/58678251/nasa-image-download#comment103656849_58678251) – Cyrus Nov 03 '19 at 10:56

1 Answers1

0

I would strongly suggest to make use of the apod API. The following query returns all the information of the APOD of a given day:

$ curl 'https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=2019-11-01'

This you can process with jq to extract the information you want.

A very detailed explanation can be found here

kvantour
  • 25,269
  • 4
  • 47
  • 72