All pastes #907689 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-02-17 20:55 UTC
rendered paste body
#!/bin/sh

for year in 2002 2003 2004 2005 2006 2007 2008; do
	[ -f /tmp/output.html ] && rm /tmp/output.html
	echo "Grabbing index ...	Year: $year"
	wget -q http://cad-comic.com/archives.php?y=$year -O /tmp/output.html
	[ -d $year ] || mkdir $year
	total=$(cat /tmp/output.html | grep -e '/comic.php?d=' | wc -l)
	num=0
	while read line; do
		if echo $line | grep -e '/comic.php?d=' >/dev/null; then
			num=$(($num+1))
			url=$(echo $line | grep -e '/comic.php?d=' | sed 's/.*href="\(.*\)".*/\1/')
			date=$(echo $line | grep -e '/comic.php?d=' | sed 's/.*d=\(.*\)".*/\1/')
			title=$(echo $line | grep -e '/comic.php?d=' | sed 's/.*">\(.*\)<\/a>.*/\1/' | sed 's!/!_!')
			short_date=$(echo $date | sed 's/-//g')
			echo "Grabbing $num/$total ...	Date: $date	Title: $title"
			[ -f /tmp/comic.html ] && rm /tmp/comic.html
			[ -f "$year/$date - $title.jpg" ] || wget -q http://cad-comic.com/comics/$short_date.jpg -O "$year/$date - $title.jpg"
		fi
	done < /tmp/output.html
done