Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # xkcd Ripper
- # <http://xkcd.com/>
- #
- # Arkanon <arkanon@lsd.org.br>
- # 2011/02/12 (Sáb) 01:25:50 (BRD)
- # 2010/10/13 (Qua) 00:08:56 (BRS)
- # 2010/10/12 (Ter) 23:43:14 (BRS)
- #
- # The ace in the hole :-p
- # <http://recantodasletras.uol.com.br/artigos/69424>
- # <http://denilsodelima.blogspot.com/2010/11/como-e-que-se-diz-o-pulo-do-gato-em.html>
- #
- # echo -e \\x$(printf %x 39)
- # output|'
- #
- # eval "echo -e \"$(echo "'Petit'\nbeing a reference" | sed -r 's:&#([0-9]+);:$(echo -e \\\\x$(printf %x \1)):g')\""
- # output|'Petit'
- # |being a reference
- #
- # lynx -dump -force_html <(echo '"')
- # output| "
- # |
- if [ $# != 1 ]
- then
- echo "Usage: $(basename $0) <issue-number>"
- exit
- fi
- out=$(wget -qO- http://xkcd.com/$1) || { echo "not found"; exit; }
- data=$(eval "echo -e \"$(
- echo "$out" \
- | grep -e "<h1>" -e "/comics/.*title" \
- | sed -r '
- s:\\:_BS_:g
- s: *<h1>([^<]*)</h1>.*:\1:g
- s:.*/([^/]*)":\1:
- s:" title=":\n:
- s:".*::
- # here goes the line below
- s:_BS_:\\\\\\\\:g
- '
- )\"")
- t1=$(echo "$data" | sed '1!d')
- i1=$(echo "$data" | sed '2!d')
- l1=$(echo "$data" | sed '3!d')
- # This command (l2) could be [merged with the sed above] OR [deleted if all we wanted was the next label (l3)]
- l2=$(eval "echo -e \"$(
- echo "$l1" \
- | sed -r '
- s:\\:_BS_:g
- s:&#([0-9]+);:$(echo -e \\\\x$(printf %x \1)):g # put just this line in sed above
- s:_BS_:\\\\\\\\:g
- '
- )\"")
- l3=$(lynx -dump -force_html -width=1024 <(echo $l2) | sed -r 's/(^ +| +$)//')
- echo -e "\n\e[1;33mTitle\e[0m"
- echo "$t1"
- echo -e "\n\e[1;33mImage filename\e[0m"
- echo "$i1"
- echo -e "\n\e[1;33mInside the img title attribute\e[0m"
- echo "$l2"
- echo -e "\n\e[1;33mOutput\e[0m"
- echo "$l3"
- if [ $1 = 859 ]
- then
- echo -e "\n\e[1;32mFor reference, that's the correct answer\e[0m"
- echo -e "\n\e[1;33mTitle\e[0m"
- echo "("
- echo -e "\n\e[1;33mImage filename\e[0m"
- echo "(.png"
- echo -e "\n\e[1;33mInside the img title attribute\e[0m"
- echo "Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or \\\\;;"\''{\<<[' this mouseover text.""
- echo -e "\n\e[1;33mOutput\e[0m"
- echo "Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or \\\\;;\"\''{\<<[' this mouseover text.\""
- fi
- echo
- # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement