Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import os, pynmea2
- def converter():
- sourceFolder = "C:\\Users\\Marwan\\Documents\\PPE\\sd\\9\\"
- targetFile = "C:\\Users\\Marwan\\Documents\\PPE\\sd\\OUTPUT.CSV"
- progressBar = 0
- csv = open(targetFile, 'w')
- csv.write("TimeStamp,DHT Temperature,Humidity,HIC,BMP Temperature,Pressure,Altitude,UTC Time,Latitude,Longitude\n")
- for filename in os.listdir(sourceFolder):
- file = open(sourceFolder + filename, 'r')
- array = file.readlines()
- for i in range(len(array)):
- array[i] = array[i][0:len(array[i])-1]
- outputString = array[0] + "," + array[1] + "," + array[2] + "," + array[3] + "," + array[4] + "," + array[5] +\
- "," + array[6]
- array = array[13:len(array)-3]
- gpsArray = str()
- for i in range(len(array)):
- if array[i][0:6] == "$GPGGA":
- gpsArray = array[i]
- break
- print(filename)
- try:
- nmea = pynmea2.parse(gpsArray)
- outputString = outputString + "," + nmea.timestamp.strftime("%H:%M:%S") + "," + str(nmea.latitude) + "," +\
- str(nmea.longitude) + "\n"
- except:
- outputString = outputString + "," + "N/A" + "," + "N/A" + "," + "N/A" + "\n"
- file.close()
- csv.write(outputString)
- progressBar = 100
- csv.close()
- if __name__ == "__main__":
- converter()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement