#!/bin/sh
# (C) 2014 Steffen Lange, steffen@stelas.de
#
# copy file to /tmp/calllog.sh; cat /tmp/calllog.sh > /var/flash/calllog

FILE='/tmp/calllog.fifo'
NOW=`date +'%a %H:%M'`
TEL="$1"

if [ -n "$TEL" ]; then
	HTML=`wget -q -O - "http://www.dasoertliche.de/?form_name=search_inv&ph=$TEL"`
	if [ $? -eq 0 ]; then
		NAME=`echo "$HTML" | sed -n 's/^[[:space:]]*na: \"\(.*\)\".*/\1/; t hit; b; :hit; p; q'`
	fi
fi

echo "$NOW $TEL $NAME" > $FILE
