Thursday, July 23, 2009

XKCD offline archive with mouseover text

this post has nothing to do with the generic theme of the blog, but who cares...

I wanted to create an off-line archive of xkcd.com web comic, and found plenty of shell script to do so, but none packaged the image with the mouseover/tooltip text (which for me was half the fun). So i did, what any self-respecting xkcd reader would do, i went on to create one. So here it is for all the xkcd fans.

The link to download the offline archive (from 1-592 in )

https://dl.getdropbox.com/u/138928/xkcd.cbr


the script used to create it.


################################
#!/bin/bash
#Download all xkcd and package with tooltip text
#3rd June, 2009, created by subiet

for i in `seq 1 592`
do
wget http://xkcd.com/$i/
echo "$(grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f4)" | convert -antialias -background yellow -page 1024x70 text:- $i.jpg

wget `grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f2`

convert -append $(ls -t | tail -n 1) $i.jpg $i.jgp
rm index.html
rm *.jpg
rm *.png

done

###################################

3 comments:

Ehsan Kia said...

hey man! Great stuff!
I was looking everywhere for a script that would save the mouseover text, but even myself didn't have an idea of how to do it!

Great stuff. Would really appreciate an update on this until #666 (which is coming out tomorow :)

Again, thanks alot!

Subiet said...

Fine, I will see.

C. Albert said...

The problem with this is that the images are do not fit the picture and The text at the bottom does not wrap. I am trying to make this upgrade. Add
echo "$(grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f4) " | w3m -dump -T text/html | convert -antialias -background yellow -page 1024x70 text:- $i.jpg

to replace:


echo "$(grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f4)" | convert -antialias -background yellow -page 1024x70 text:- $i.jpg

This line: w3m -dump -T text/html
will escape the HTML characters.