annotate bin/xkcdmania @ 727:49538e2aad65 default tip

Add a useful editrc
author nanaya <me@nanaya.net>
date Tue, 24 Sep 2024 16:58:15 +0900
parents 5bafb912837e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
124
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
1 #!/bin/sh
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
2
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
3 dir="/anime/misc/webcomics/xkcd"
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
4 [ -d "${dir}" ] || exit 1
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
5
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
6 fetchlink() {
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
7 if [ "$1" -a "$2" ]; then
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
8 wget --quiet -O "$2" "$1"
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
9 else
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
10 return 1
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
11 fi
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
12 }
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
13 latest=$(fetchlink http://xkcd.com/ - | grep 'Permanent link' | sed -e 's/.*\/\([0-9]*\)\/.*/\1/')
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
14 [ -n "${latest}" ] || exit 1
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
15 next=1
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
16 while [ "${next}" -le "${latest}" ]; do
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
17 to_dl="${to_dl} ${next}"
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
18 next=$((next + 1))
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
19 done
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
20
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
21 for i in $to_dl
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
22 do
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
23 if [ ! -n "$(find "$dir/$(printf '%04d' $i)"* -type f 2>/dev/null)" ] && [ "${i}" -ne 404 ]; then
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
24 page=$(fetchlink "http://xkcd.com/$i/" -)
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
25 img=$(echo "$page" | grep 'Image URL' | sed -e 's/.*\(http[^<]*\).*/\1/' | head -n 1)
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
26 echo "$(echo "$page" | grep "src" | grep "$img" | sed -e 's/.*title="\([^\"]*\)".*/\1/')" > "$dir/$(printf '%04d' $i) $(basename $img | sed -e 's/\(.*\)\..*/\1/').txt"
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
27 fetchlink "${img}" "$dir/$(printf '%04d' $i) $(basename "$img")"
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
28 fi
5bafb912837e Massive addition of old scripts collection.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
29 done