Python code for extracting latitude, longitude, speed and course from NEMA message

#!/usr/bin/python
import serial
port = serial.Serial(“/dev/ttyAMA0”, 9600, timeout=3.0)

while True:

          rcvdfile=port.read(1200
          pos1 = rcvdfile.find(“$GPRMC”)
          pos2 = rcvdfile.find(“\n”,pos1)
          loc = rcvdfile[pos1:pos2]
          data = loc.split(‘,’)

          pos11 = rcvdfile.find(“$GPGGA”)
          pos22 = rcvdfile.find(“\n”,pos11)
          loc1 = rcvdfile[pos11:pos22]
          data1 = loc1.split(‘,’)
          if data[2]==’V’:
          print ‘No location found’

else:

         #print “UTC time=”+data[1]+” UTC date=” + data[9]
           gps_time=float(data[1])
           gps_date=float(data[9])

           gps_hour=int(gps_time/10000.0)
           gps_min= gps_time%10000.0
           gps_sec=gps_min%100.0
           gps_min=int(gps_min/100.0)
           gps_sec=int(gps_sec)

           gps_dd=int(gps_date/10000.0)
           gps_mm= gps_date%10000.0
           gps_yy=gps_mm%100.0
           gps_mm=int(gps_mm/100.0)
           gps_yy=int(gps_yy)

           print ‘time=’,gps_hour,’:’,gps_min,’:’,gps_sec
           print ‘date=’,gps_dd,’/’,gps_mm,’/’,gps_yy

           print “Latitude = “+data[3]+data[4]
           print “Longitude = “+data[5]+data[6]
           print “Speed = “+data[7]
           print “Course = “+data[8]
           print “\n”

           gps_time_gga=float(data1[1])
           gps_hour_gga=int(gps_time_gga/10000.0)
           gps_min_gga= gps_time_gga%10000.0
           gps_sec_gga=gps_min_gga%100.0
           gps_min_gga=int(gps_min_gga/100.0)
           gps_sec_gga=int(gps_sec_gga)

           print ‘time=’,gps_hour_gga,’:’,gps_min_gga,’:’,gps_sec_gga

           print “Latitude = “+data1[2]+data1[3]
           print “Longitude = “+data1[4]+data1[5]
           print “Satellites used= “+data1[7]
           print “Altitude = “+data1[9]
           print “\n”