All pastes #748032 Raw Edit

Untitled

public text v1 · immutable
#748032 ·published 2007-10-24 15:06 UTC
rendered paste body
#!/bin/sh

for year in 2002 2003 2004 2005 2006 2007; do
	[ -f /tmp/output.html ] && rm /tmp/output.html
	wget -q http://cad-comic.com/archives.php?y=$year -O /tmp/output.html
	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/')
			short_date=$(echo $date | sed 's/-//g')
			echo Grabbing $num/$total ... Date: $date ... Title: $title
			[ -f /tmp/comic.html ] && rm /tmp/comic.html
			wget -q http://cad-comic.com/comics/$short_date.jpg -O "$year/$date - $title.jpg"
		fi
	done < /tmp/output.html
done