#!/bin/bash ### # Angry Sheriff # version 0.1 # # Get foreclosure listings (Sheriff's Sales) from NJ.com web site # (c) Murty Rompalli # # 8/14/2003 ### prog='Angry Sheriff v0.1' if [ x$1 = x ] then echo echo ERROR: Missing directory name echo echo Usage: $0 directory-name echo Choose directory name that does not exist \(To download fresh\), or echo choose existing directory name \(To use downloaded listings\) echo exit 1 else dir=`echo $1 | sed 's/\/$//'` out=$dir.list fi # Price must be below limit and above minprice limit=110000 minprice=1000 topskip=7 bottomskip=10 tmp=tmp.$$ ( echo echo ' ' $prog echo ' ' '(c)' Murty Rompalli echo echo ' ' Download and process echo ' ' Sheriff\'s sales in NJ echo ) | tee $out ### Get address getaddress() { # com.+nly k.+ as\ ?:? # mun.+ty\ ?:? # ad.+s\ ?:? echo $1 | sed 's/\;//g' | sed -n 's/^.\+\(com[a-zA-Z0-9]\+nly\ k[a-zA-Z0-9]\+ as\ \?:\?\|mun[a-zA-Z0-9]\+ty\ \?:\?\|ad[dreDRE0-9]\+s\ \?:\?\)\(.\+\)\(N\.\?\ \?J\.\?\|NEW\.\?\ \?JERSEY\.\?\)\(\ \?[0-9][0-9][0-9][0-9][0-9]\|\ \).\+$/\2\ \3\ \4/ip' } ### Show info showinfo() { file=$1 maxprice=$2 printf "\n$maxprice\t$file\t" linecount=`cat $file | wc -l` # Dont scan the first few lines and last few lines linecount=`expr $linecount - $bottomskip` n=$topskip while [ $n -le $linecount ] do h=`expr $n + 3` block="`sed -n "$n,$h p" $file | sed -e "s/'//g" -e 's/"//g' | xargs echo`" address="`getaddress \"$block\"`" if [ "x$address" != x ] then echo $address break fi n=`expr $n + 1` done if [ "x$address" = x ] then echo ADDRESS CANNOT BE DETERMINED fi } ### Apply price rule applypricerule() { ( printf "\nPRICE\tFILE\t\tADDRESS\n" printf "\n-----\t----\t\t-------\n" ) | tee -a ../$out for file in `\ls page*` do prices=`grep '\$[1-9][0-9\,][0-9\,][0-9\.\,]\+' $file | sed 's/^.*\(\$[1-9][0-9\,][0-9\,][0-9\.\,]\+\).*$/\1/' | sed -e 's/\\\$//g' -e 's/\,//g' | awk -F. '{print $1}' | sed -e "s/'//g" -e 's/"//g' | xargs echo` # flag is 1 if the advt is for a house below our set limit price flag=1 maxprice=0 for price in $prices do if [ $price -gt $limit ] then flag=0 break fi if [ $price -gt $maxprice ] then maxprice=$price fi done if [ $flag -eq 1 ] then if [ $maxprice -lt $minprice ] then rejectedfiles="$rejectedfiles $file " else showinfo $file $maxprice fi else \rm -f $file badfiles="$badfiles $file " fi done | tee -a ../$out echo echo ===== Rejected Files ===== echo $rejectedfiles echo echo ===== Deleted Files ===== echo $badfiles echo \rm -f ../$tmp } ### Get files getfiles() { mkdir $dir page=1 while [ $page -lt 31 ] do lynx -dump -verbose -nolist 'http://www.nj.com/classifieds/publicnotices/index.ssf/results.ata?timeframe=168&major=7&minor=2280%2C2043%2C658%2C1297&count=100&keyword=new+jersey&paper=&aff=njo&session=&page='$page | sed 's/\[INLINE\]//g' | grep '[a-zA-Z0-9]' | sed -n '/Click here to learn more about \"My List\"/,/More Search Results/p'\ > $tmp count=`grep 'Add To My List' $tmp | wc -l` echo Processing page $page $count [ $count -gt 0 ] || break cd $dir csplit -s -f page$page. ../$tmp '/Add To My List/' '{*}' cd .. page=`expr $page + 1` done echo Results saved in directory: $dir } ### Main program if [ ! -d $dir ] then echo Downloading files. Please wait... getfiles fi cd $dir || { echo Unable to change dir to $dir exit } applypricerule echo echo Thank you for using $prog echo # END