#! /usr/bin/python3
from gps import *
import gridtools
import time
import sys
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) 
count=0
degree=u'\N{DEGREE SIGN}'
while count < 5:
    if gpsd.waiting():
        report = gpsd.next() #
        if report['class'] == 'TPV':
            lat=getattr(report,'lat',0.0)
            lon=getattr(report,'lon',0.0)
            tim=getattr(report,'time','')
            if int(lat) != 0: 
                grid=gridtools.Grid(gridtools.LatLong(lat,lon))
                #print(f'{lat:.4f}', degree, ", ", f'{lon:.4f}', degree, " = ", grid, sep='')
                print(grid)
                sys.exit()
    time.sleep(.5)
    count+=1
print("No GPS lock")
