#!/usr/bin/env python3 # # Program to automatically save the situation at certain intervals from xplra import XPlane, ProtocolException import sys import os import time if __name__ == "__main__": interval = float(sys.argv[1]) xplanePath = sys.argv[2] name = sys.argv[3] newName = name + ".new.sit" savePath = "output/situations/" + newName basePath = os.path.join(xplanePath, "Output", "situations", name) path = basePath + ".sit" newPath = basePath + ".new.sit" oldPath = basePath + ".old.sit" xplane = XPlane() print("Connecting to X-Plane...") while not xplane.isConnected: try: xplane.connect() except: print("Connection failed, sleeping...") time.sleep(0.5) print("Connected to X-Plane") try: while True: try: xplane.saveSituation(savePath) try: if os.path.exists(path): os.rename(path, oldPath) os.rename(newPath, path) print("Situation saved at " + time.strftime("%H:%M:%S")) except OSError as e: print("I/O error occured: " + str(e)) except ProtocolException as e: print("Protocol error occured: " + str(e)) time.sleep(interval) except Exception as e: print("Connection failed: " + str(e)) try: xplane.disconnect() except: pass