summaryrefslogtreecommitdiffstats
path: root/bin/comics/userfriendly
blob: 54137c977b71e19f38639a102d8979dfc6ada4e8 (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
#!/bin/bash

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

browser="Mozilla/4.06 [en] (X11; I; Linux 2.0.35 i586)"
date="$(date -d "$daysago days ago" +%Y%m%d)"
newn="${day}.gif"

# get image link
page="http://ars.userfriendly.org/cartoons/?id=${date}"
page_regex="<a href=\"/cartoons/?id=${date}\">"
url_regex='.*<img[^>]*src="\([^"]*\)".*'

img=$(wget ${wget_args} -U "$browser" -O - "${page}" | grep "${page_regex}" | sed "s#${url_regex}#\1#")

if [ -n "${img}" ]; then
    echo "Hole userfriendly von $img"
    echo "fuer Datum: $(date -d"$daysago days ago" -I)"
    echo

    wget ${wget_args} "${img}" -U "$browser" -O "${newn}"

    if [ -s "${tmp}/${newn}" ]; 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}"