#!/usr/bin/perl # Script to fetch the latest GPS location from SPOT's API, and save it (because they don't), # and then generate a javascript file that will write out the html needed to provide a linked # static google maps image. This is to avoid forcing joomla/wordpress/etc to execute php code - # as long as you can include the generated js file via javascript, it'll work. # Author: Charlie Schluting (c) 2011 # use XML::Simple; #use strict.. heh, no, this barely works. $CACHEFILE = "/home/charlie/lastspotlocation.txt"; $JS = "/stash/www/charlierides.com/files/map.js"; $XML = "/home/charlie/spot.xml"; # hahaha, oh man.. `wget -q -O $XML http://share.findmespot.com/messageService/guestlinkservlet?glId=0Vn4kA4MiPgNSYD52NgPjuVJDpUCSUlGW`; # create object $xml = new XML::Simple; # read XML file $data = $xml->XMLin("$XML"); # this is how we overcome spot's API not keeping >30 days. If they've aged out, do nothing (i.e. keep using the old data). die("No messages found, totalCount is 0, ABORTING LIKE AN UGLY KID") unless $data->{totalCount} > 0; # the first object is always the most recent: $lat = $data->{message}->[0]->{latitude}; $long = $data->{message}->[0]->{longitude}; # just because (hey, what if something else wants to use this?) open(FILE, ">$CACHEFILE"); print FILE $lat . "," . $long . "\n"; close(FILE); # ugly shit that writes out javascript to write out html, to include a linked static google maps image $googleoptions = "&zoom=8&size=140x152&sensor=false&maptype=hybrid"; $googlelink = ""; $header = "

Current location (since the last GPS update):

"; $js = 'document.write(\''. $header .'\');' . ' document.write(\''. $googlelink .'\');' . ' document.write(\'\'); document.write(\'
\'); document.write(\'

Or view all recent tracks.

\'); '; open(FILE, ">$JS"); print FILE $js; close(FILE);