king vash
2008-07-24 02:14:05
I hacked it all together but cookies to anyone that can improve it
#!/bin/sh
cd /home/king3/Pictures/webcomics/XKCD/
i=1;
while [ $i -lt 5 ]
do
fileexist=`find . -name ""$i"_\[*"` #looks for files starting with"2_[" if your on i = 2
echo ${#$(find . -name ""$i"_\[*")}
if [ ${#fileexist} -eq 0 ]
then
wget http://xkcd.com/$i/
url=$(grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f2)
file=$(echo $url | cut -d\" -f2 | cut -d\/ -f5)
alttext=$(grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f6)
name=${file%_(1).jpg}
name=${name%.jpg}.jpg
wget $url
mv $file "$i"_"[""$alttext""]"_$name
rm index.html
else
echo already have number $i
fi;
i=`expr $i + 1`
done