forked from sgsax/apod-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apod
executable file
·58 lines (48 loc) · 1.53 KB
/
apod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Automatically download the Astronomy Picture of the Day and set it as
# the wallpaper for your linux system, and keep a local copy if you desire.
# User can modify paths at top of script to suit personal needs.
# Feel free to modify this script as you see fit.
# Seth D. Galitzer, sgsax@ksu.edu
# Forked from: https://github.com/sgsax/apod-desktop
# Modified by Joseph Spencer
# directory where picture is saved
imgdir=$HOME/Pictures
# base URL for the APOD website
baseurl=http://apod.nasa.gov/apod/
# base URL plus name of the page where the current picture can be found
sourceurl=${baseurl}astropix.html
tmpfile=/tmp/astropix.html
imgfile=$imgdir/apod.jpg
# attempt to retrieve the astropix page
attemptNum=1
echo getting page ${sourceurl}
wget ${sourceurl} -T 10 -q -O $tmpfile
while [ $? -ne 0 ]; do
if [ $attemptNum -gt 20 ]; then
echo "Unable to retrieve page";
exit 1;
fi
let attemptNum++;
sleep 15;
echo "Reattempting... (Attempt ${attemptNum})";
wget ${sourceurl} -T 10 -q -O $tmpfile
done
# extract the image url from the astropix page
echo getting image url
imgurl=`cat $tmpfile | grep -i "img src" | sed -e 's/.*<img src="\(.*\)".*/\1/i'`
# check image exists
if [ "$imgurl" == "" ]; then
echo "No image today"
exit 3
else
# get that image file
echo getting image ${baseurl}${imgurl}
wget ${baseurl}${imgurl} -T 10 -q -O $imgfile
if [ $? -ne 0 ]; then
echo "Unable to retrieve image"
exit 2
else
xfdesktop -reload
fi
fi