From f2e53145783834be9bf17f0161a9f79c6c0d9a73 Mon Sep 17 00:00:00 2001 From: NomsterDude <85312283+NomsterDude@users.noreply.github.com> Date: Fri, 10 Jun 2022 11:21:35 -0700 Subject: [PATCH] Update self.last_pos_datetime handling Updated all `self.last_pos_datetime` caculations to not exit the program if `ac_dict.time_position` is NoneType. --- planeClass.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/planeClass.py b/planeClass.py index dd8f62f..6eda6f7 100644 --- a/planeClass.py +++ b/planeClass.py @@ -88,7 +88,8 @@ class Plane: from mictronics_parse import get_aircraft_reg_by_icao, get_type_code_by_icao self.reg = get_aircraft_reg_by_icao(self.icao) self.type = get_type_code_by_icao(self.icao) - self.last_pos_datetime = datetime.fromtimestamp(ac_dict.time_position) + if ac_dict.time_position is not None: + self.last_pos_datetime = datetime.fromtimestamp(ac_dict.time_position) except ValueError as e: print("Got data but some data is invalid!") print(e) @@ -544,7 +545,8 @@ class Plane: if self.feeding: #Squawks emergency_squawks ={"7500" : "Hijacking", "7600" :"Radio Failure", "7700" : "General Emergency"} - seen = datetime.now() - self.last_pos_datetime + if self.last_pos_datetime is not None: + seen = datetime.now() - self.last_pos_datetime #Only run check if emergency data previously set if self.last_emergency is not None and not self.emergency_already_triggered: time_since_org_emer = datetime.now() - self.last_emergency[0] @@ -567,7 +569,8 @@ class Plane: #Realizes first time seeing emergency, stores time and type elif self.squawk in emergency_squawks.keys() and not self.emergency_already_triggered and not self.on_ground: print("Emergency", self.squawk, "detected storing code and time and waiting to trigger") - self.last_emergency = (self.last_pos_datetime, self.squawk) + if self.last_pos_datetime is not None: + self.last_emergency = (self.last_pos_datetime, self.squawk) elif self.squawk not in emergency_squawks.keys() and self.emergency_already_triggered: self.emergency_already_triggered = None @@ -876,4 +879,4 @@ class Plane: print(time_since_ra) if time_since_ra.seconds >= 600: print(ra_type) - self.recent_ra_types.pop(ra_type) \ No newline at end of file + self.recent_ra_types.pop(ra_type)