summaryrefslogtreecommitdiffstats
path: root/bin/comics/zits
blob: b3399cefee1eca749193e06c85c2b7a36a627fc2 (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
#!/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

newn="${day}.gif"
month="$(date -d "$daysago days ago" +%m)"
server="http://zitscomics.com/comics/$(date -d "$daysago days ago" +%B-%-d-%Y | tr '[:upper:]' '[:lower:]')/"
imgregex="http://safr.kingfeatures.com/idn/etv/zone/xml/content.php\?file=[A-Za-z0-9]+"
useragent="Mozilla/4.76 [de] (X11; U; Linux 2.2.18 i586)"

echo "Dateiname: $newn"
echo
echo "Hole zits von $server"
echo "fuer Datum: $(date -d"$daysago days ago" -I)"
echo

imgurl=$(wget ${wget_args} -U "$useragent" -O - "$server" | grep -o -E "$imgregex" | head -n1)

echo "Url zum Bild ist: ${imgurl}"

wget ${wget_args} -U "$useragent" \
    --header="Referer: $server" --max-redirect=0 \
    -O "$newn" "$imgurl" 

if [ -s "${tmp}/${newn}" ]; then
    if file "$newn" | grep GIF > /dev/null 2>&1; then
        mv "${tmp}/${newn}" "${image_dir}/$newn"
        rm -f "${comic_dir}/latest.gif"
        ln -s "${image_offset}/$newn" "${comic_dir}/latest.gif"
    fi
fi

rm -rf "${tmp}"