Comic download
Sep 11, 2010       2:15 am

I like to blog about my Bash scripts. Mostly it's so that I can refer back to them later when I can't remember how I did something. Also I always have this hope that someone is going to read them and tell me how I could have written it better. But that has never happened.

It seems that everything I do in Bash starts out as one-line script and ends up as a more unwieldy thing that leaves me wishing I had picked another language.

I wanted to be able to quickly scan through all of the Pictures For Sad Children comics. The files are all named with sequential numbers, so I figured I'd just download them all.

a="http://www.picturesforsadchildren.com/comics"
for i in {1..358}
do
  wget `printf "$a/%08d.gif" $i`
done

Problem is, they're not all gif files. The script quickly becomes more complicated.

There are three possible file extensions to try to download for each file. The data set has a lot of contiguous subsets of comic strips of the same type, so this script benefits from the heuristic optimization of moving a type to the front of the list when it downloads successfully.

I'm sure this would be a lot more concise if I knew more about how to do array manipulation. But Bash is really not my language.

a="http://www.picturesforsadchildren.com/comics"
types=( gif png jpg )
for i in {1..358}
do 
  b=`printf "%08d" $i`
  if [ "$(ls $b.* 2> /dev/null | wc -l)" -ne "0" ]
  then
    echo "$b skipped"
    continue
  fi
  tested=()
  untested=()
  found=""
  for c in "${types[@]}"
  do
    if [ ! $found ]
    then
      echo -n "$b.$c ..."
      wget -q "$a/$b.$c"
      if [ -f "$b.$c" ]
      then
        found="$c"
        echo " found"
      else
        tested=( "${tested[@]}" "$c" )
        echo " not found"
      fi
    else
      untested=( "${untested[@]}" "$c" )
    fi
  done
  types=( "$found" "${tested[@]}" "${untested[@]}" )
done

For my next trick, I dumped all of these images onto a web page. This one was a one-liner:

f=`date +%s`; p=`pwd`; for a in `ls` ; do echo "<img src=\"$p/$a\"/>"; done > /tmp/$f.html ; chromium-browser /tmp/$f.html
new comment >
NbuWRtbUCTlYNlkeIS
by Anonymous on Sep 21, 2011, 10:33 pm
ffZvnM tgxmqlzr wupcqbxd ixtbvlyw
bnTXgrYxFu
by Anonymous on Oct 20, 2011, 8:26 am
zqvkljgv hkebzqed zwdqwora
ZAsAfqZXTXO
by Anonymous on Oct 20, 2011, 9:37 am
qrarapzk nxdnbgkt atbbvkoe
YsKVavuHKdKGtCNjUH
by Anonymous on Oct 20, 2011, 10:49 am
daksvbmd grfwuqsy wgdhvjml
qIbLcPCNWpfN
by Anonymous on Oct 20, 2011, 11:58 am
fmjrtgmo hwjzabhz vhtcnhri
ueInScnVcNVeqLEYA
by Anonymous on Oct 20, 2011, 1:09 pm
oyojkcet ukhvdxoo byytamxu
KNmurLgnoeOs
by Anonymous on Oct 21, 2011, 5:52 pm
lmcbszaw ueoqnxjy mpsnzydu
fkmAeepfTiDZ
by Anonymous on Oct 21, 2011, 8:20 pm
hongqfrn dbspmlmr npghjvrx
gPqsmNEvdKHtfNucBeE
by Anonymous on Oct 21, 2011, 9:26 pm
lqzuzvup ivnlrwda ibsdbcva
aQBFPVnZmabzN
by Anonymous on Oct 23, 2011, 1:30 am
wwlqentv wtaxqktw akiimxkv
hNKnLHjlPRYMk
by Anonymous on Oct 23, 2011, 2:43 am
zyojdoxw zuwlypwy slpjqdof
EmuRnjtiURseI
by Anonymous on Oct 23, 2011, 3:56 am
jwcxsaln mreygkth qddvuidq
cFUltdrpke
by Anonymous on Oct 23, 2011, 5:06 am
zmlmmujn vkvurtun pvirkrbx
iQScmfHUbPtThrlWdme
by Anonymous on Oct 23, 2011, 6:18 am
gqzoilxj pleolkza lxhrnkjr
gEOPvgKfZkhIAzRj
by Anonymous on Nov 1, 2011, 11:49 am
azwocmct qrxwarga mkmxmfdr
pfusROGCrWO
by Anonymous on Nov 9, 2011, 10:13 am
ckvaexiv vrsdjten brtmjbyd
EMmnrFIXKbAKjJ
by Anonymous on Nov 9, 2011, 4:52 pm
kqlsvhds afbshvhn zbbbwerc
xsOblsFZkKKAkz
by Anonymous on Nov 10, 2011, 7:24 am
owltqlqj enbsctzk okrahxwo
IfnREJHKEUbykB
by Anonymous on Nov 10, 2011, 2:39 pm
ukyjqhpk rdfrqshz ijfpwlvf
KmDJOMgHsTYONUMCvZ
by Anonymous on Nov 10, 2011, 10:02 pm
hfwfdiog lsjfzlqe zddgazha
bGZuvlxkupCLlz
by Anonymous on Nov 11, 2011, 5:19 am
ztbmhlka njtfmtme aojozevt
FAbXoySkyLtaNZz
by Anonymous on Nov 11, 2011, 12:34 pm
frbrnbxo biidcuoh qhokvyfs