Advertisement
marwanpro

converter

May 11th, 2016
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import os, pynmea2
  4.  
  5. def converter():
  6.     sourceFolder = "C:\\Users\\Marwan\\Documents\\PPE\\sd\\9\\"
  7.     targetFile = "C:\\Users\\Marwan\\Documents\\PPE\\sd\\OUTPUT.CSV"
  8.     progressBar = 0
  9.  
  10.     csv = open(targetFile, 'w')
  11.     csv.write("TimeStamp,DHT Temperature,Humidity,HIC,BMP Temperature,Pressure,Altitude,UTC Time,Latitude,Longitude\n")
  12.  
  13.     for filename in os.listdir(sourceFolder):
  14.         file = open(sourceFolder + filename, 'r')
  15.         array = file.readlines()
  16.  
  17.         for i in range(len(array)):
  18.             array[i] = array[i][0:len(array[i])-1]
  19.  
  20.         outputString = array[0] + "," + array[1] + "," + array[2] + "," + array[3] + "," + array[4] + "," + array[5] +\
  21.                        "," + array[6]
  22.  
  23.         array = array[13:len(array)-3]
  24.         gpsArray = str()
  25.  
  26.         for i in range(len(array)):
  27.             if array[i][0:6] == "$GPGGA":
  28.                 gpsArray = array[i]
  29.                 break
  30.  
  31.         print(filename)
  32.         try:
  33.             nmea = pynmea2.parse(gpsArray)
  34.             outputString = outputString + "," + nmea.timestamp.strftime("%H:%M:%S") + "," + str(nmea.latitude) + "," +\
  35.                        str(nmea.longitude) + "\n"
  36.         except:
  37.             outputString = outputString + "," + "N/A" + "," + "N/A" + "," + "N/A" + "\n"
  38.  
  39.         file.close()
  40.         csv.write(outputString)
  41.  
  42.     progressBar = 100
  43.     csv.close()
  44.  
  45. if __name__ == "__main__":
  46.     converter()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement