import sys sys.path.append(r"c:\Python27\Lib\site-packages") sys.path.append(r"c:\Python27\Lib") from datetime import datetime, timedelta import socket ## ##savepath - folder you want to save to ## savepath = "G:/My Drive/Flight Operations/1 - Flight Data Files/1 - Data Logs/Flight Logger Output/" ## ## filepath = savepath + datetime.now().strftime('%Y%m%d') + " " + socket.gethostname() + ".txt" tiaTOT = datetime.min print "Flight Logger Script Active" print "File saved @: " + filepath while True: if (not cs.armed): print "disarmed" ##wait for armed state while (not cs.armed): Script.Sleep(50) print "armed" ##wait for take off while (cs.timeInAir == 0): Script.Sleep(50) ##catch take off info and print to console print "Takeoff @: " + datetime.now().strftime('%H:%M:%S %Y-%m-%d') print "GPS Pos: " + str(cs.lat) + " , " + str(cs.lng) ##save takeoff info to file flightlogger = open(filepath, 'a') flightlogger.write( "Takeoff --- Datetime: " + datetime.now().strftime('%H:%M:%S %Y-%m-%d') + " Lat: " + str(cs.lat) + " Long: " + str(cs.lng)+"\n") flightlogger.close() ##wait until disarmed while cs.armed: Script.Sleep(50) ##catch disarm info and output to console print "Disarm @: " + datetime.now().strftime('%H:%M:%S %Y-%m-%d') minute,second = divmod(int(cs.timeInAir),60) hour,minutes = divmod(minute,60) print "Time in air: " + str(hour) + ":" + str(minutes) + ":" + str(second) tiaTOT = tiaTOT + timedelta(0,int(second), 0, 0,minutes,hour) print "Time in Air Total: " + tiaTOT.strftime('%H:%M:%S') print "Dist trav: " + str(cs.distTraveled) ##save disarm info to file flightlogger = open(filepath, 'a') flightlogger.write( "Land --- Datetime: " + datetime.now().strftime('%H:%M:%S %Y-%m-%d') + " TIA: " + str(cs.timeInAirMinSec) + " tiaTOT: " + tiaTOT.strftime('%H:%M:%S') + " Dist: " + str(cs.distTraveled)+"\n") flightlogger.close()