#!/bin/bash
#latitudelogger.sh
# Logs Google Latitude positions
#
# Author :
# Jean-Marc Liotier 
#
# Changelog :
# 20090604 - 0.1 - Initial release, based on latitude2brighkite.sh
#
# Requirements beyond Bash :
# - The Perl JSON library (http://search.cpan.org/dist/JSON/)
# (available in Debian as libjson-perl)
# - Curl
#
# Known bugs and limitations :
# - Requires your Google Public Location Badge to be enabled and to show the
# best available location. For this script to work, your location has to be
# public.
#
# This script is an ugly mongrel hack. I'm an aged script kiddie.
#
# It proves that it can be done, it works for me, and the official Google
# Latitude API will hopefully soon make it obsolete !
#
# The right way to do it would be to parse Latitude's JSON output cleanly using
# the Perl library. But that dirty prototype took me all of ten minutes to set
# up, and it works...
# 
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.

# Parameters
#
# Replace this Google Public Location Badge URL with your own
# (choose the JSON one !)
badge="http://www.google.com/latitude/apps/badge/api?user=7832225593622256926&type=json"
#
# Working directory for temporary files
workdir=/home/jim/applications/latitudelogger
#
# End of parameters

date=`date -u +%s`
coordinates=`wget -qO- "$badge" | perl -0007 -MJSON -ne 'print to_json(from_json($_, {allow_nonref=>1}), {pretty=>1})' | grep -A 2 coordinates | grep -v coordinates | sed s/,//`
echo $date $coordinates >> $workdir/latitudelog