#!/bin/bash



if [ "$1." == "." ]
then
  echo Too few parameters ...
  exit 0
fi


PHONENR=`echo $1 | tr -s " " "+"`

wget -t1 -T2 -q -O /tmp/testphone "http://www.paginebianche.it/ricerca-da-numero?qs=$PHONENR"

NAME=`cat /tmp/testphone | grep title | grep address | sed 's/" /"\n/g ; s/">/=/g ; s/class="/\n/g ; s/<\/span/\n/g' | grep title | cut -d '=' -f2 | grep -v modal-title | tr -d '"' | tail -1`
ADDR=`cat /tmp/testphone | grep title | grep address | sed 's/" /"\n/g ; s/">/=/g ; s/class="/\n/g ; s/<\/span/\n/g' | grep street-address | cut -d '=' -f2`
CITY=`cat /tmp/testphone | grep title | grep address | sed 's/" /"\n/g ; s/">/=/g ; s/class="/\n/g ; s/<\/span/\n/g' | grep locality | cut -d '=' -f2`
ZIP=`cat /tmp/testphone | grep title | grep address | sed 's/" /"\n/g ; s/">/=/g ; s/class="/\n/g ; s/<\/span/\n/g' | grep "> -" | grep span | cut -d' ' -f3`

if [ -n "$NAME" ] ; then echo "TELEXTRA_NAME=$NAME" ; fi
if [ -n "$ADDR" ] ; then echo "TELEXTRA_ADDR=$ADDR" ; fi
if [ -n "$ZIP" ] ; then echo "TELEXTRA_CAP=$ZIP " ; fi
if [ -n "$CITY" ] ; then echo "TELEXTRA_CITY=$CITY " ; fi


