#!/usr/bin/python import time, math, urllib, socket from gps import gps key = open("access.key").read().strip() g = gps() lastSent = None while 1: time.sleep(1) if 1: # test mode t = time.time() / 10 position = [37.4419 + .01 * math.sin(t), -122.1419 + .01 * math.cos(t)] else: try: g.query("p") except socket.error: print "gps query failed" # gps module can get wedged and not get position again # until I restart the program. Hopefully re-getting the # object will be enough. g = gps() if g.fix.latitude == 0: print "no fix" continue position = [g.fix.latitude, g.fix.longitude] if position != lastSent: print "sending", position try: urllib.urlopen( "http://maps.bigasterisk.com/gpsClient?key=%s&lat=%f&long=%f" % (key, position[0], position[1])) lastSent = position except KeyboardInterrupt: raise except Exception, e: print "send failed:", e.__class__, e