summaryrefslogtreecommitdiffstats
path: root/bin/comics/jeremykaye
blob: abe0150a33fe12579a4843e9457c7e4565da8d08 (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
#!/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 LC_ALL=C

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

echo "searching on $searchdate"

posturl="$(wget -O - http://jeremykaye.tumblr.com/archive | sed -nre "s#.*(http://[^\"]+)\">.+post_date\">${searchdate}.*#\1#p")"

echo "post url: $posturl"

if [ -n "$posturl" ]; then
	read URL TITLE <<EOF
$(wget -O - "$posturl" | sed -nre "s#.*img src=\"(http://.+media.tumblr.com/[^\"]+.png)\" *alt=\"(.+)#\1 \2#p")
EOF
	echo "url: $URL"
	echo "title: $TITLE"
	wget ${wget_args} --header="Referer: $posturl" -O "${day}.png" $URL
	if [ -s "${tmp}/${day}.png" ]; then
		mv "${tmp}/${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}"