~kraige/potd/release-1.0

1 by Seb
Initial import
1
#!/bin/bash
2
#Create the directory if $HOME/.potd/ doesn't exist
3
mkdir -p ~/.potd/
4
#I like 42 columns for conky, has to be configured for your preferred width.
5
export conkycolumns=42;
6
#Get today's astronomy picture and save it to apod.html
7
load_apod(){
8
	wget http://antwrp.gsfc.nasa.gov/apod/ -O $HOME/.potd/apod.html
9
	#Grep the IMG tag from apod and wget it to apod.jpg
10
	grep IMG $HOME/.potd/apod.html| awk -F\" '{ system("wget http://antwrp.gsfc.nasa.gov/apod/"$2" -O $HOME/.potd/apod.jpg") }'
11
	#Set the new desktop background on gnome
12
	/usr/bin/gconftool-2 --type string --set /desktop/gnome/background/picture_filename $HOME/.potd/apod.jpg
13
	#Format the file to end in the nearest </tag> each line
14
	perl -p -i -e 'chomp if(!/\>$/)' $HOME/.potd/apod.html;
15
	#Save the APotD Description on a txt file for conky with the pre-set columns or as closed to it as possible without breaking words.
16
	perl -e 'my $flag=0; my $curline = "";while(<>){$curline = $_; if ($flag){s/<[^>]*>/ /g; s/\ \ /\ /g; s/([^\n]{0,$ENV{conkycolumns}})(?:\b\s*|\n)/$1\n/gi; print;} last if ($curline =~ /<p>\ <center>/); $flag=1 if (/Explanation\:/); }' ~/.potd/apod.html > $HOME/.potd/conky.txt
17
}
18
load_wpod(){
19
	wget http://en.wikipedia.org/wiki/Wikipedia:Picture_of_the_day -O $HOME/.potd/wpod.html
20
	grep '<td>.*class=\"image\"' $HOME/.potd/wpod.html| gawk -F\" '{ system("wget http://en.wikipedia.org"$2" -O $HOME/.potd/wpodp.html") }'
21
	grep 'class=\"fullImageLink\"' $HOME/.potd/wpodp.html|gawk -F'href' '{ print $3 }'|gawk -F\" '{ system("wget "$2" -O $HOME/.potd/wpod.jpg") }'
22
	#Set the new desktop background on gnome
23
	/usr/bin/gconftool-2 --type string --set /desktop/gnome/background/picture_filename $HOME/.potd/wpod.jpg
24
	#Save the EPotD Description on a txt file for conky with the pre-set columns or as closed to it as possible without breaking words.
25
	perl -e 'my $flag=0;while(<>){ $flag = 0 if(/<\/table>/); if ($flag){s/<[^>]*>/ /g; s/([^\n]{0,$ENV{conkycolumns}})(?:\b\s*|\n)/$1\n/gi; print if(/[A-Za-z0-9]/);} $flag=1 if (/<td>.*class=\"image\"/); }' $HOME/.potd/wpod.html > $HOME/.potd/conky.txt
26
}
27
load_epod(){
28
	#Get today's earth picture and save it to epod.html
29
	wget http://epod.usra.edu/ -O $HOME/.potd/epod.html
30
	grep asset-image $HOME/.potd/epod.html|gawk -F\" '{ system("wget "$2" -O $HOME/.potd/epod.jpg") }'
31
	#Set the new desktop background on gnome
32
	/usr/bin/gconftool-2 --type string --set /desktop/gnome/background/picture_filename $HOME/.potd/epod.jpg
33
	#Save the EPotD Description on a txt file for conky with 42 chars or as closed to it as possible without breaking words (based ~/.conkyrc width.)
34
	perl -e 'my $flag=0;while(<>){ $flag = 0 if(/\"related-clicks"/); if ($flag){s/<[^>]*>/ /g; s/([^\n]{0,$ENV{conkycolumns}})(?:\b\s*|\n)/$1\n/gi; print if(/[A-Za-z0-9]/);} $flag=1 if (/\"entry-body\"/); }' $HOME/.potd/epod.html > $HOME/.potd/conky.txt
35
}
36
case "$1" in
37
  apod|astronomy|nasa|"")
38
	load_apod
39
	;;
40
  wpod|wikipedia|wiki)
41
	load_wpod
42
	;;
43
  epod|earth)
44
	load_epod
45
	;;
46
  *)
47
	echo "Usage: potd.sh [apod|wpod|epod]" >&2
48
	exit 3;
49
	;;
50
esac