Index of /crappycode/geo-cam
Name Last modified Size Description
Parent Directory 29-Nov-2005 11:52 -
geo-cam.sh 30-Oct-2004 18:08 4k
#!/usr/local/bin/bash
#contact: ken@ipl31.net
#DISCLAIMER, this shell script is very sloppy and probably has
#potential security risks, its a proof of concept, no warranty bla bla
#
#This script is designed to recieve email with a jpg attachment and an address in
#the message body, then construct an update for a blog running on blosxom
#
#I use procmail with a rule such as:
# * ^TOphonecam@example.com
# | /home/username/bin/geo-cam.sh >> /home/username/geocam.log 2>> /home/username/geocam.log
#To cat the email and pipe it to this script
#
#I took the image conversion parts of this script from phonecam.sh which can be found at:
#http://seattlewireless.net/~mattw/badsoftware/phonecam/
export PATH=/bin:/usr/bin:/usr/local/bin
#Filesystem path for blosxom posts
filepath="/home/username/public_html/blosxom/phonecam"
#Filesystem path for images
imagepath="/home/username/public_html/geoimages"
#Base url for creating img tags, notice trailing slash, yes I am lazy
imagelink="/geoimages/"
#Extension you use for blosxom entries
fileext=".blx"
tmp="/tmp"
#Url for geocoder service
geocoderurl="http://rpc.geocoder.us/service/rest?address="
#url for tiger map server
tigerurl="http://tiger.census.gov/cgi-bin/mapgen?"
LOGFILE=/home/username/geocam.log
GEOFILE=latlongtmp.rdf
#Title of bloxsom post, this goes on the first line, I think its also used when bloxsom generates the <title>
title="Phonecam Post"
# thumbnail sizes
tlandscape="240x160"
tportrait="160x240"
umask 022
mkdir $tmp/.$$
cd $tmp/.$$
munpack > /dev/null 2>&1
for i in *.jpg; do
sleep 1
time=`date +%s`
f=`identify $i`
a=`basename $i .jpg`
mv $i $imagepath/$time.jpg
#
# Identify portrait or landscape.
# Here there be dragons.
#
f=${f/+0*/}
f=${f/* /}
x=${f/x*/}
y=${f/*x/}
if [ "$x" -gt "$y" ]; then
thumbsize=$tlandscape
else
thumbsize=$tportrait
fi
convert -resize $thumbsize $imagepath/$time.jpg $imagepath/$time.thumb.jpg
if [ -f $a.desc ];then
address=$(cat $a.desc)
geoquery=""
for i in $(cat $a.desc)
do
geoquery=$geoquery"+"$i
done
echo $geoquery >> $LOGFILE
else
#exit since we dont have an address and its pointless
exit
fi
curl $geocoderurl$geoquery -o $GEOFILE
GEOCOUNT=$(cat $GEOFILE | grep lat | grep geo | wc -l)
#OK check to see if we got multiple matches, for now we are going to use hte first match but we
#will store them in array in case we want them all later or I improve the desicion making
if [ $GEOCOUNT -gt 1 ];
then
echo "More than one response" >> $LOGFILE
MULTI_MATCH=true
LATINDEX=0
for COORD in $(grep -E '(<geo:lat)' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba')
do
LAT[$LATINDEX]=$COORD
let "LATINDEX = $LATINDEX + 1"
done
LONGINDEX=0
for COORD in $(grep -E '(<geo:lon)' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba')
do
LON[$LONGINDEX]=$COORD
let "LONGINDEX = $LONGINDEX + 1"
done
else
echo "One response" >> $LOGFILE
LAT=$(cat $GEOFILE | grep -E '(<geo:lat)' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba')
LON=$(cat $GEOFILE | grep -E '(<geo:lon)' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba')
fi
#OK Now lets have the tiger server draw us a map
echo $tigerurl"lon=$LON&lat=$LAT&wid=0.035&ht=0.035&iht=240&iwd=160&mark=$LON,$LAT,redpin" > tigerurl.tmp
wget -i ./tigerurl.tmp -O tmpmap.jpg
cp tmpmap.jpg $imagepath/$time.map.jpg
cat << EOF > $filepath"/"$time"."$fileext
$title
<table>
<tr>
<td>
<p> $address
<b><p>Lat:</b> $LAT
<p><b>Lon:</b> $LON
<p>
</td>
<td>$a</td>
<td><a href=$imagelink$time.jpg><img src=$imagelink$time.thumb.jpg ></a></td>
<td><img src=$imagelink$time.map.jpg></td>
</tr>
</table>
EOF
done
rm -rf $tmp/.$$