summaryrefslogtreecommitdiffstats
path: root/bin/comics/extrafabulous
blob: 46f1604e304244bc2c46177204a401540bb71232 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash

if [ -z "$1" -o ! -d "$1" ]; then
    echo "Usage: $0 <top-directory> [<days ago>]" 1>&2
    exit 1
fi

top="${1}"
shift

source "${top}/etc/settings.sh"
tmp="$(mktemp -d)"
cd "${tmp}"

export LANG=C
export LC_ALL=C

DATE=$(date -d"$daysago days ago" +"%d %b %Y")

URL=$(wget "http://extrafabulouscomics.com/feed/" -O - | sed -n -re "/pubDate.+$DATE/ { n; n; n; n; s/.+(http:\/\/extrafabulouscomics.com\/comic\/[0-9]+\/).+/\1/p; q }")

if [ -z $URL ]; then
	echo "Nichts gefunden für $DATE"
	rm -rf "${tmp}"
	exit 0
fi
echo URL $URL gefunden

URL=$(wget -O - "$URL" | sed -nre 's#.*<img src="(http://extrafabulouscomics.com/wp-content/[^"]+)".+#\1#p')

if [ -z $URL ]; then
	echo "Comic URL nicht gefunden!!"
	rm -rf "${tmp}"
	exit 1
fi
echo Comic URL $URL


wget -O "${tmp}/${day}.gif" $URL

if [ -s "${tmp}/${day}.gif" ]; then
	mv "${tmp}/${day}.gif" "${image_dir}/${day}.gif"
	ln -s "${image_dir}/${day}.gif" "${comic_dir}/latest.gif"
fi

rm -rf "${tmp}"