summaryrefslogtreecommitdiffstats
path: root/bin/comics/cyanide
blob: dcbff822e79b145e4dddf615dcc912b9b7be8d13 (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
47
48
49
50
51
#!/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
export LC_TIME=C
year=`date -d "$daysago days ago 00:00:00" +%Y`
month=`date -d "$daysago days ago 00:00:00" +%m`
day=`date -d "$daysago days ago 00:00:00" +%d`

part=`curl -s "http://explosm.net/comics/archive/$year/$month" | sed -nre "s#.+/comics/([0-9]+)/?\">$year.$month.$day.+#\1#p"`
if [ -z "$part" ]; then
	echo "Cyanide and Happyness: Kein Comic für $year, $month $day"
	rm -rf "${tmp}"
	exit
fi

htmladdress="http://explosm.net/comics/$part"
echo "Cyanide and happyness: $htmladdress gefunden"

browser="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0"

echo "Lese URL von $htmladdress"
url=$(wget ${wget_args} -O - --user-agent="$browser" "$htmladdress" | grep -oE 'files.explosm.net/comics/[^"]+' | head -n1)

if [ -n "$url" ]; then
	url="http://$url"
	echo "Dateiname: $url"
	echo "Hole cyanide and happyness für Datum: $(date -d"$daysago days ago" -I)"

	wget ${wget_args} --user-agent="$browser" -O "$day.png" "$url"

	if [ -s "${day}.png" ]; then
		mv ${day}.png "${image_dir}/$day.png"
		rm -f "${comic_dir}/latest.png"
		ln -s "${image_offset}/$day.png" "${comic_dir}/latest.png"
	fi
fi

rm -rf "${tmp}"