ADSBX v2, crash notifications, Squawk, Nav modes
-ADSBX v2 API Support -ADSBX API Proxy support, https://gitlab.com/jjwiseman/adsbx-api-proxy -Built in crash notification to discord (Required RN need to add toggle) -Fix some error handling -Emergency Squawk Notifcations -FMS Nav Mode Notifications (WIP, need to add set alt to althold notis and more) -Landing / Takeoff notification code simplified to one module
This commit is contained in:
parent
bdda2f45d9
commit
90b74df7db
|
@ -2,6 +2,7 @@ import configparser
|
||||||
import time
|
import time
|
||||||
from colorama import Fore, Back, Style
|
from colorama import Fore, Back, Style
|
||||||
import platform
|
import platform
|
||||||
|
import traceback
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
from colorama import init
|
from colorama import init
|
||||||
init(convert=True)
|
init(convert=True)
|
||||||
|
@ -15,6 +16,11 @@ download_font()
|
||||||
main_config = configparser.ConfigParser()
|
main_config = configparser.ConfigParser()
|
||||||
main_config.read('./configs/mainconf.ini')
|
main_config.read('./configs/mainconf.ini')
|
||||||
source = main_config.get('DATA', 'SOURCE')
|
source = main_config.get('DATA', 'SOURCE')
|
||||||
|
from discord_webhook import DiscordWebhook
|
||||||
|
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Started")))
|
||||||
|
webhook.execute()
|
||||||
|
try:
|
||||||
|
print("Source is set to", source)
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
#Setup plane objects from plane configs
|
#Setup plane objects from plane configs
|
||||||
|
@ -45,6 +51,13 @@ while True:
|
||||||
header = ("-------- " + str(running_Count) + " -------- " + str(datetime_tz.strftime("%I:%M:%S %p")) + " ---------------------------------------------------------------------------")
|
header = ("-------- " + str(running_Count) + " -------- " + str(datetime_tz.strftime("%I:%M:%S %p")) + " ---------------------------------------------------------------------------")
|
||||||
print (Back.GREEN + Fore.BLACK + header[0:100] + Style.RESET_ALL)
|
print (Back.GREEN + Fore.BLACK + header[0:100] + Style.RESET_ALL)
|
||||||
if source == "ADSBX":
|
if source == "ADSBX":
|
||||||
|
api_version = int(main_config.get('ADSBX', 'API_VERSION'))
|
||||||
|
if api_version == 2:
|
||||||
|
icao_key = 'hex'
|
||||||
|
elif api_version == 1:
|
||||||
|
icao_key = 'icao'
|
||||||
|
else:
|
||||||
|
raise Exception("Invalid API Version")
|
||||||
from defADSBX import pullADSBX
|
from defADSBX import pullADSBX
|
||||||
data, failed = pullADSBX(planes)
|
data, failed = pullADSBX(planes)
|
||||||
if failed == False:
|
if failed == False:
|
||||||
|
@ -52,8 +65,11 @@ while True:
|
||||||
for key, obj in planes.items():
|
for key, obj in planes.items():
|
||||||
has_data = False
|
has_data = False
|
||||||
for planeData in data['ac']:
|
for planeData in data['ac']:
|
||||||
if planeData['icao'] == key:
|
if planeData[icao_key].upper() == key:
|
||||||
obj.run_ADSBX(planeData)
|
if api_version == 1:
|
||||||
|
obj.run_ADSBXv1(planeData)
|
||||||
|
elif api_version == 2:
|
||||||
|
obj.run_ADSBXv2(planeData)
|
||||||
has_data = True
|
has_data = True
|
||||||
break
|
break
|
||||||
if has_data is False:
|
if has_data is False:
|
||||||
|
@ -89,7 +105,6 @@ while True:
|
||||||
elif source == "ADSBX":
|
elif source == "ADSBX":
|
||||||
source = "OPENS"
|
source = "OPENS"
|
||||||
failed_count = 0
|
failed_count = 0
|
||||||
from discord_webhook import DiscordWebhook
|
|
||||||
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Failed over to " + source)))
|
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Failed over to " + source)))
|
||||||
webhook.execute()
|
webhook.execute()
|
||||||
elapsed_calc_time = time.time() - start_time
|
elapsed_calc_time = time.time() - start_time
|
||||||
|
@ -98,7 +113,7 @@ while True:
|
||||||
print (Back.GREEN + Fore.BLACK + footer[0:100] + Style.RESET_ALL)
|
print (Back.GREEN + Fore.BLACK + footer[0:100] + Style.RESET_ALL)
|
||||||
|
|
||||||
|
|
||||||
sleep_sec = 15
|
sleep_sec = 30
|
||||||
for i in range(sleep_sec,0,-1):
|
for i in range(sleep_sec,0,-1):
|
||||||
if i < 10:
|
if i < 10:
|
||||||
i = " " + str(i)
|
i = " " + str(i)
|
||||||
|
@ -108,3 +123,12 @@ while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
sys.stdout.write(Back.RED + ('\x1b[1K\r' +"Slept for " +str(sleep_sec)) + Style.RESET_ALL)
|
sys.stdout.write(Back.RED + ('\x1b[1K\r' +"Slept for " +str(sleep_sec)) + Style.RESET_ALL)
|
||||||
print()
|
print()
|
||||||
|
except KeyboardInterrupt as e:
|
||||||
|
print(e)
|
||||||
|
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Manual Exit: " + str(e) )))
|
||||||
|
webhook.execute()
|
||||||
|
except BaseException as e:
|
||||||
|
print(e)
|
||||||
|
print(traceback.format_exc())
|
||||||
|
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Error Exiting: " + str(e) )))
|
||||||
|
webhook.execute()
|
|
@ -12,6 +12,10 @@ TZ = UTC
|
||||||
#ADS-B Exchange https://www.adsbexchange.com/data/
|
#ADS-B Exchange https://www.adsbexchange.com/data/
|
||||||
[ADSBX]
|
[ADSBX]
|
||||||
API_KEY = apikey
|
API_KEY = apikey
|
||||||
|
API_VERSION = 1
|
||||||
|
#ADSBX API Proxy V2, https://gitlab.com/jjwiseman/adsbx-api-proxy
|
||||||
|
ENABLE_PROXY = FALSE
|
||||||
|
PROXY_HOST = N/A
|
||||||
|
|
||||||
#OpenSky https://opensky-network.org/apidoc/index.html
|
#OpenSky https://opensky-network.org/apidoc/index.html
|
||||||
#When using without your own login user and pass should be None
|
#When using without your own login user and pass should be None
|
||||||
|
|
15
defADSBX.py
15
defADSBX.py
|
@ -8,10 +8,22 @@ import urllib3
|
||||||
main_config = configparser.ConfigParser()
|
main_config = configparser.ConfigParser()
|
||||||
main_config.read('./configs/mainconf.ini')
|
main_config.read('./configs/mainconf.ini')
|
||||||
def pullADSBX(planes):
|
def pullADSBX(planes):
|
||||||
|
if main_config.getboolean('ADSBX', 'ENABLE_PROXY') is False:
|
||||||
|
api_version = int(main_config.get('ADSBX', 'API_VERSION'))
|
||||||
|
if api_version == 1:
|
||||||
if len(planes) > 1:
|
if len(planes) > 1:
|
||||||
url = "https://adsbexchange.com/api/aircraft/json/"
|
url = "https://adsbexchange.com/api/aircraft/json/"
|
||||||
elif len(planes) == 1:
|
elif len(planes) == 1:
|
||||||
url = "https://adsbexchange.com/api/aircraft/icao/" + str(list(planes.keys())[0]) + "/"
|
url = "https://adsbexchange.com/api/aircraft/icao/" + str(list(planes.keys())[0]) + "/"
|
||||||
|
elif api_version == 2:
|
||||||
|
url = "https://adsbexchange.com/api/aircraft/v2/all"
|
||||||
|
else:
|
||||||
|
raise Exception("No API Version set")
|
||||||
|
else:
|
||||||
|
if main_config.has_option('ADSBX', 'PROXY_HOST'):
|
||||||
|
url = "http://" + main_config.get('ADSBX', 'PROXY_HOST') + ":8000/api/aircraft/v2/all"
|
||||||
|
else:
|
||||||
|
raise BaseException("Proxy enabled but no host")
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'api-auth': main_config.get('ADSBX', 'API_KEY'),
|
'api-auth': main_config.get('ADSBX', 'API_KEY'),
|
||||||
|
@ -25,7 +37,7 @@ def pullADSBX(planes):
|
||||||
print(error_message)
|
print(error_message)
|
||||||
failed = True
|
failed = True
|
||||||
data = None
|
data = None
|
||||||
except (IncompleteRead, http.IncompleteRead, ConnectionResetError, requests.ChunkEncodingError, urllib3.exceptions.ProtocolError, ValueError) as error_message:
|
except (IncompleteRead, http.IncompleteRead, ConnectionResetError, urllib3.exceptions.ProtocolError, ValueError) as error_message:
|
||||||
print("Connection Error")
|
print("Connection Error")
|
||||||
print(error_message)
|
print(error_message)
|
||||||
failed = True
|
failed = True
|
||||||
|
@ -41,6 +53,7 @@ def pullADSBX(planes):
|
||||||
data = json.loads(response.text)
|
data = json.loads(response.text)
|
||||||
except (json.decoder.JSONDecodeError, ValueError) as error_message:
|
except (json.decoder.JSONDecodeError, ValueError) as error_message:
|
||||||
print("Error with JSON")
|
print("Error with JSON")
|
||||||
|
if 'data' in locals() and data != None:
|
||||||
print (json.dumps(data, indent = 2))
|
print (json.dumps(data, indent = 2))
|
||||||
print(error_message)
|
print(error_message)
|
||||||
failed = True
|
failed = True
|
||||||
|
|
174
planeClass.py
174
planeClass.py
|
@ -21,6 +21,10 @@ class Plane:
|
||||||
self.last_longitude = None
|
self.last_longitude = None
|
||||||
self.last_contact = None
|
self.last_contact = None
|
||||||
self.landing_plausible = False
|
self.landing_plausible = False
|
||||||
|
self.last_squawk = None
|
||||||
|
self.squawk = None
|
||||||
|
self.nav_modes = None
|
||||||
|
self.last_nav_modes = None
|
||||||
def getICAO(self):
|
def getICAO(self):
|
||||||
return self.icao
|
return self.icao
|
||||||
def run_OPENS(self, ac_dict):
|
def run_OPENS(self, ac_dict):
|
||||||
|
@ -41,20 +45,16 @@ class Plane:
|
||||||
else:
|
else:
|
||||||
self.feeding = True
|
self.feeding = True
|
||||||
self.run_check()
|
self.run_check()
|
||||||
def run_ADSBX(self, ac_dict):
|
def run_ADSBXv1(self, ac_dict):
|
||||||
#Parse ADBSX Vector
|
#Parse ADBSX V1 Vector
|
||||||
from colorama import Fore, Back, Style
|
from colorama import Fore, Back, Style
|
||||||
self.printheader("head")
|
self.printheader("head")
|
||||||
#print (Fore.YELLOW +"ADSBX Sourced Data: ", ac_dict, Style.RESET_ALL)
|
#print (Fore.YELLOW +"ADSBX Sourced Data: ", ac_dict, Style.RESET_ALL)
|
||||||
try:
|
try:
|
||||||
#postime is divided by 1000 to get seconds from milliseconds, from timestamp expects secs.
|
#postime is divided by 1000 to get seconds from milliseconds, from timestamp expects secs.
|
||||||
self.__dict__.update({'icao' : ac_dict['icao'], 'callsign' : ac_dict['call'], 'reg' : ac_dict['reg'], 'latitude' : float(ac_dict['lat']), 'longitude' : float(ac_dict['lon']), 'geo_alt_ft' : int(ac_dict['galt']), 'on_ground' : bool(int(ac_dict["gnd"])), 'last_contact' : round(float(ac_dict["postime"])/1000)})
|
self.__dict__.update({'icao' : ac_dict['icao'], 'callsign' : ac_dict['call'], 'reg' : ac_dict['reg'], 'squawk' : ac_dict['sqk'], 'latitude' : float(ac_dict['lat']), 'longitude' : float(ac_dict['lon']), 'geo_alt_ft' : int(ac_dict['galt']), 'on_ground' : bool(int(ac_dict["gnd"])), 'last_contact' : round(float(ac_dict["postime"])/1000)})
|
||||||
if self.on_ground:
|
if self.on_ground:
|
||||||
self.geo_alt_ft = 0
|
self.geo_alt_ft = 0
|
||||||
if "to" in ac_dict.keys():
|
|
||||||
self.to_location = ac_dict["to"]
|
|
||||||
if "from" in ac_dict.keys():
|
|
||||||
self.from_location = ac_dict["from"]
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
|
||||||
print("Got data but some data is invalid!")
|
print("Got data but some data is invalid!")
|
||||||
|
@ -64,6 +64,46 @@ class Plane:
|
||||||
else:
|
else:
|
||||||
self.feeding = True
|
self.feeding = True
|
||||||
self.run_check()
|
self.run_check()
|
||||||
|
|
||||||
|
def run_ADSBXv2(self, ac_dict):
|
||||||
|
#Parse ADBSX V2 Vector
|
||||||
|
from colorama import Fore, Back, Style
|
||||||
|
self.printheader("head")
|
||||||
|
#print (Fore.YELLOW +"ADSBX Sourced Data: ", ac_dict, Style.RESET_ALL)
|
||||||
|
try:
|
||||||
|
self.__dict__.update({'icao' : ac_dict['hex'].upper(), 'reg' : ac_dict['r'], 'squawk' : ac_dict['squawk'], 'latitude' : float(ac_dict['lat']), 'longitude' : float(ac_dict['lon'])})
|
||||||
|
if 'alt_geom' in ac_dict:
|
||||||
|
self.geo_alt_ft = int(ac_dict['alt_geom'])
|
||||||
|
elif 'alt_geom' not in ac_dict and 'alt_baro' in ac_dict:
|
||||||
|
self.geo_alt_ft =int(ac_dict['alt_baro'])
|
||||||
|
if 'flight' in ac_dict:
|
||||||
|
self.callsign = ac_dict['flight']
|
||||||
|
if ac_dict['alt_baro'] == "ground":
|
||||||
|
self.geo_alt_ft = 0
|
||||||
|
self.on_ground = True
|
||||||
|
elif ac_dict['alt_baro'] != "ground":
|
||||||
|
self.on_ground = False
|
||||||
|
if'nav_modes' in ac_dict:
|
||||||
|
self.nav_modes = ac_dict['nav_modes']
|
||||||
|
for idx, mode in enumerate(self.nav_modes):
|
||||||
|
if mode == ('tcas' or 'lnav' or 'vnav'):
|
||||||
|
self.nav_modes[idx] = self.nav_modes[idx].upper()
|
||||||
|
else:
|
||||||
|
self.nav_modes[idx] = self.nav_modes[idx].capitalize()
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
#Create last seen timestamp from how long ago in secs a pos was rec
|
||||||
|
now = datetime.now()
|
||||||
|
last_pos_datetime = now - timedelta(seconds= ac_dict["seen_pos"])
|
||||||
|
self.last_contact = datetime.timestamp(last_pos_datetime)
|
||||||
|
except (ValueError, KeyError) as e:
|
||||||
|
|
||||||
|
print("Got data but some data is invalid!")
|
||||||
|
print(e)
|
||||||
|
print (Fore.YELLOW +"ADSBX Sourced Data: ", ac_dict, Style.RESET_ALL)
|
||||||
|
self.printheader("foot")
|
||||||
|
else:
|
||||||
|
self.feeding = True
|
||||||
|
self.run_check()
|
||||||
def printheader(self, type):
|
def printheader(self, type):
|
||||||
from colorama import Fore, Back, Style
|
from colorama import Fore, Back, Style
|
||||||
if type == "head":
|
if type == "head":
|
||||||
|
@ -137,15 +177,15 @@ class Plane:
|
||||||
time_since_contact = self.get_time_since(self.last_contact)
|
time_since_contact = self.get_time_since(self.last_contact)
|
||||||
output = [
|
output = [
|
||||||
[(Fore.CYAN + "ICAO" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.icao + Style.RESET_ALL)],
|
[(Fore.CYAN + "ICAO" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.icao + Style.RESET_ALL)],
|
||||||
[(Fore.CYAN + "Callsign" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.callsign + Style.RESET_ALL)],
|
[(Fore.CYAN + "Callsign" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.callsign + Style.RESET_ALL)] if self.callsign != None else None,
|
||||||
[(Fore.CYAN + "Reg" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.reg + Style.RESET_ALL)] if "reg" in self.__dict__ else None,
|
[(Fore.CYAN + "Reg" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.reg + Style.RESET_ALL)] if "reg" in self.__dict__ else None,
|
||||||
[(Fore.CYAN + "From" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.from_location + Style.RESET_ALL)] if "from_location" in self.__dict__ else None,
|
[(Fore.CYAN + "Squawk" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.squawk + Style.RESET_ALL)] if "squawk" in self.__dict__ else None,
|
||||||
[(Fore.CYAN + "To" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + self.to_location + Style.RESET_ALL)] if "to_location" in self.__dict__ else None,
|
|
||||||
[(Fore.CYAN + "Latitude" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(self.latitude) + Style.RESET_ALL)],
|
[(Fore.CYAN + "Latitude" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(self.latitude) + Style.RESET_ALL)],
|
||||||
[(Fore.CYAN + "Longitude" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(self.longitude) + Style.RESET_ALL)],
|
[(Fore.CYAN + "Longitude" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(self.longitude) + Style.RESET_ALL)],
|
||||||
[(Fore.CYAN + "Last Contact" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(time_since_contact).split(".")[0]+ Style.RESET_ALL)],
|
[(Fore.CYAN + "Last Contact" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(time_since_contact).split(".")[0]+ Style.RESET_ALL)],
|
||||||
[(Fore.CYAN + "On Ground" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(self.on_ground) + Style.RESET_ALL)],
|
[(Fore.CYAN + "On Ground" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str(self.on_ground) + Style.RESET_ALL)],
|
||||||
[(Fore.CYAN + "GEO Alitude" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str("{:,} ft".format(self.geo_alt_ft)) + Style.RESET_ALL)]
|
[(Fore.CYAN + "GEO Alitude" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + str("{:,} ft".format(self.geo_alt_ft)) + Style.RESET_ALL)],
|
||||||
|
[(Fore.CYAN + "Nav Modes" + Style.RESET_ALL), (Fore.LIGHTGREEN_EX + ', '.join(self.nav_modes) + Style.RESET_ALL)] if "nav_modes" in self.__dict__ and self.nav_modes != None else None,
|
||||||
]
|
]
|
||||||
output = list(filter(None, output))
|
output = list(filter(None, output))
|
||||||
print(tabulate(output, [], 'fancy_grid'))
|
print(tabulate(output, [], 'fancy_grid'))
|
||||||
|
@ -161,11 +201,11 @@ class Plane:
|
||||||
if self.last_on_ground:
|
if self.last_on_ground:
|
||||||
self.tookoff = True
|
self.tookoff = True
|
||||||
self.trigger_type = "no longer on ground"
|
self.trigger_type = "no longer on ground"
|
||||||
self.tookoff_header = "Took off from "
|
self.type_header = "Took off from "
|
||||||
elif self.last_feeding is False and self.feeding and self.landing_plausible == False:
|
elif self.last_feeding is False and self.feeding and self.landing_plausible == False:
|
||||||
self.tookoff = True
|
self.tookoff = True
|
||||||
self.trigger_type = "data acquisition"
|
self.trigger_type = "data acquisition"
|
||||||
self.tookoff_header = "Took off near "
|
self.type_header = "Took off near "
|
||||||
else:
|
else:
|
||||||
self.tookoff = False
|
self.tookoff = False
|
||||||
else:
|
else:
|
||||||
|
@ -179,7 +219,7 @@ class Plane:
|
||||||
if self.on_ground and self.last_on_ground is False and self.last_below_desired_ft:
|
if self.on_ground and self.last_on_ground is False and self.last_below_desired_ft:
|
||||||
self.landed = True
|
self.landed = True
|
||||||
self.trigger_type = "now on ground"
|
self.trigger_type = "now on ground"
|
||||||
self.landed_header = "Landed in "
|
self.type_header = "Landed in "
|
||||||
self.landing_plausible = False
|
self.landing_plausible = False
|
||||||
#Set status for landing plausible
|
#Set status for landing plausible
|
||||||
elif self.last_below_desired_ft and self.last_feeding and self.feeding is False and self.last_on_ground is False:
|
elif self.last_below_desired_ft and self.last_feeding and self.feeding is False and self.last_on_ground is False:
|
||||||
|
@ -190,7 +230,7 @@ class Plane:
|
||||||
self.landing_plausible = False
|
self.landing_plausible = False
|
||||||
self.landed = True
|
self.landed = True
|
||||||
self.trigger_type = "data loss"
|
self.trigger_type = "data loss"
|
||||||
self.landed_header = "Landed near "
|
self.type_header = "Landed near "
|
||||||
else:
|
else:
|
||||||
self.landed = False
|
self.landed = False
|
||||||
|
|
||||||
|
@ -263,59 +303,26 @@ class Plane:
|
||||||
#Set Twitter Title
|
#Set Twitter Title
|
||||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||||
self.twitter_title = self.icao if self.config.get('TWITTER', 'TITLE') == "icao" else self.callsign if self.config.get('TWITTER', 'TITLE') == "callsign" else self.config.get('TWITTER', 'TITLE')
|
self.twitter_title = self.icao if self.config.get('TWITTER', 'TITLE') == "icao" else self.callsign if self.config.get('TWITTER', 'TITLE') == "callsign" else self.config.get('TWITTER', 'TITLE')
|
||||||
#Takeoff Notifcation and Landed
|
#Takeoff and Land Notification
|
||||||
|
if self.tookoff or self.landed:
|
||||||
if self.tookoff:
|
if self.tookoff:
|
||||||
if invalid_Location is False:
|
|
||||||
tookoff_message = (self.tookoff_header + aera_hierarchy + ", " + state + ", " + country_code + ". ")
|
|
||||||
else:
|
|
||||||
tookoff_message = ("Took off")
|
|
||||||
print (tookoff_message)
|
|
||||||
#Google Map or tar1090 screenshot
|
|
||||||
if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
|
||||||
getMap((aera_hierarchy + ", " + state + ", " + country_code), self.icao)
|
|
||||||
elif self.config.get('MAP', 'OPTION') == "ADSBX":
|
|
||||||
getSS(self.icao, self.overlays)
|
|
||||||
if nearest_airport_dict != None:
|
|
||||||
append_airport(self.map_file_name, nearest_airport_dict['icao'], nearest_airport_dict['name'], nearest_airport_dict['distance'])
|
|
||||||
airport_string = nearest_airport_dict['icao'] + ", " + nearest_airport_dict["name"]
|
|
||||||
else:
|
|
||||||
airport_string = ""
|
|
||||||
else:
|
|
||||||
raise Exception("Map option not set correctly in this planes conf")
|
|
||||||
#Discord
|
|
||||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
|
||||||
dis_message = (self.dis_title + " " + tookoff_message + airport_string).strip()
|
|
||||||
sendDis(dis_message, self.map_file_name, self.config)
|
|
||||||
#PushBullet
|
|
||||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
|
||||||
with open(self.map_file_name, "rb") as pic:
|
|
||||||
map_data = self.pb.upload_file(pic, "Tookoff IMG")
|
|
||||||
self.pb_channel.push_note(self.config.get('PUSHBULLET', 'TITLE'), tookoff_message)
|
|
||||||
self.pb_channel.push_file(**map_data)
|
|
||||||
#Twitter
|
|
||||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
|
||||||
twitter_media_map_obj = self.tweet_api.media_upload(self.map_file_name)
|
|
||||||
alt_text = "Call: " + self.callsign + " On Ground: " + str(self.on_ground) + " Alt: " + str(self.geo_alt_ft) + " Last Contact: " + str(time_since_contact) + " Trigger: " + self.trigger_type
|
|
||||||
self.tweet_api.create_media_metadata(media_id= twitter_media_map_obj.media_id, alt_text= alt_text)
|
|
||||||
self.tweet_api.update_status(status = ((self.twitter_title + " " + tookoff_message).strip()), media_ids=[twitter_media_map_obj.media_id])
|
|
||||||
#self.tweet_api.update_with_media(self.map_file_name, status = (self.twitter_title + " " + tookoff_message).strip())
|
|
||||||
self.takeoff_time = time.time()
|
self.takeoff_time = time.time()
|
||||||
os.remove(self.map_file_name)
|
self.landed_time_msg = None
|
||||||
|
elif self.landed and self.takeoff_time != None:
|
||||||
|
|
||||||
if self.landed:
|
|
||||||
self.landed_time_msg = ""
|
|
||||||
if self.takeoff_time != None:
|
|
||||||
self.landed_time = time.time() - self.takeoff_time
|
self.landed_time = time.time() - self.takeoff_time
|
||||||
if platform.system() == "Linux":
|
if platform.system() == "Linux":
|
||||||
self.landed_time_msg = time.strftime("Apx. flt. time %-H Hours : %-M Mins. ", time.gmtime(self.landed_time))
|
self.landed_time_msg = time.strftime("Apx. flt. time %-H Hours : %-M Mins. ", time.gmtime(self.landed_time))
|
||||||
elif platform.system() == "Windows":
|
elif platform.system() == "Windows":
|
||||||
self.landed_time_msg = time.strftime("Apx. flt. time %#H Hours : %#M Mins. ", time.gmtime(self.landed_time))
|
self.landed_time_msg = time.strftime("Apx. flt. time %#H Hours : %#M Mins. ", time.gmtime(self.landed_time))
|
||||||
|
self.takeoff_time = None
|
||||||
|
self.landed_time = None
|
||||||
|
elif self.landed:
|
||||||
|
self.landed_time_msg = None
|
||||||
if invalid_Location is False:
|
if invalid_Location is False:
|
||||||
landed_message = (self.landed_header + aera_hierarchy + ", " + state + ", " + country_code + ". " + self.landed_time_msg)
|
message = (self.type_header + aera_hierarchy + ", " + state + ", " + country_code + ".") + ((" " + self.landed_time_msg) if self.landed_time_msg != None else "")
|
||||||
else:
|
else:
|
||||||
landed_message = ("Landed" + ", " + self.landed_time_msg)
|
message = ("Landed" + ((" " + self.landed_time_msg) if self.landed_time_msg != None else "") if self.landed else "Tookoff" if self.tookoff else "")
|
||||||
print (landed_message)
|
print (message)
|
||||||
#Google Map or tar1090 screenshot
|
#Google Map or tar1090 screenshot
|
||||||
if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
||||||
getMap((aera_hierarchy + ", " + state + ", " + country_code), self.icao)
|
getMap((aera_hierarchy + ", " + state + ", " + country_code), self.icao)
|
||||||
|
@ -326,31 +333,58 @@ class Plane:
|
||||||
airport_string = nearest_airport_dict['icao'] + ", " + nearest_airport_dict["name"]
|
airport_string = nearest_airport_dict['icao'] + ", " + nearest_airport_dict["name"]
|
||||||
else:
|
else:
|
||||||
airport_string = ""
|
airport_string = ""
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Map option not set correctly in this planes conf")
|
raise Exception("Map option not set correctly in this planes conf")
|
||||||
#Discord
|
#Discord
|
||||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
dis_message = (self.dis_title + " " + landed_message + " " + airport_string).strip()
|
dis_message = (self.dis_title + " " + message + " " + airport_string).strip()
|
||||||
sendDis(dis_message, self.map_file_name, self.config)
|
sendDis(dis_message, self.map_file_name, self.config)
|
||||||
#PushBullet
|
#PushBullet
|
||||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||||
with open(self.map_file_name, "rb") as pic:
|
with open(self.map_file_name, "rb") as pic:
|
||||||
map_data = self.pb.upload_file(pic, "Landed IMG")
|
map_data = self.pb.upload_file(pic, "Tookoff IMG")
|
||||||
self.pb_channel.push_note(self.config.get('PUSHBULLET', 'TITLE'), landed_message)
|
self.pb_channel.push_note(self.config.get('PUSHBULLET', 'TITLE'), message)
|
||||||
self.pb_channel.push_file(**map_data)
|
self.pb_channel.push_file(**map_data)
|
||||||
#Twitter
|
#Twitter
|
||||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||||
twitter_media_map_obj = self.tweet_api.media_upload(self.map_file_name)
|
twitter_media_map_obj = self.tweet_api.media_upload(self.map_file_name)
|
||||||
alt_text = "Call: " + self.callsign + " On Ground: " + str(self.on_ground) + " Alt: " + str(self.geo_alt_ft) + " Last Contact: " + str(time_since_contact) + " Trigger: " + self.trigger_type
|
alt_text = "Call: " + self.callsign + " On Ground: " + str(self.on_ground) + " Alt: " + str(self.geo_alt_ft) + " Last Contact: " + str(time_since_contact) + " Trigger: " + self.trigger_type
|
||||||
self.tweet_api.create_media_metadata(media_id= twitter_media_map_obj.media_id, alt_text= alt_text)
|
self.tweet_api.create_media_metadata(media_id= twitter_media_map_obj.media_id, alt_text= alt_text)
|
||||||
self.tweet_api.update_status(status = ((self.twitter_title + " " + landed_message).strip()), media_ids=[twitter_media_map_obj.media_id])
|
self.tweet_api.update_status(status = ((self.twitter_title + " " + message).strip()), media_ids=[twitter_media_map_obj.media_id])
|
||||||
#self.tweet_api.update_with_media(self.map_file_name, status = (self.twitter_title + " " + landed_message).strip())
|
#self.tweet_api.update_with_media(self.map_file_name, status = (self.twitter_title + " " + tookoff_message).strip())
|
||||||
self.takeoff_time = None
|
|
||||||
self.landed_time = None
|
|
||||||
self.time_since_tk = None
|
|
||||||
os.remove(self.map_file_name)
|
os.remove(self.map_file_name)
|
||||||
self.last_contact = None
|
|
||||||
|
#Squawks
|
||||||
|
squawks =[("7500", "Hijacking"), ("7600", "Radio Failure"), ("7700", "Emergency")]
|
||||||
|
if self.feeding:
|
||||||
|
for squawk in squawks:
|
||||||
|
if self.squawk == squawk[0] and self.squawk != self.last_squawk:
|
||||||
|
squawk_message = ("Squawking " + squawk[0] + ", " + squawk[1])
|
||||||
|
print(squawk_message)
|
||||||
|
#Google Map or tar1090 screenshot
|
||||||
|
# if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
||||||
|
# getMap((aera_hierarchy + ", " + state + ", " + country_code), self.icao)
|
||||||
|
if self.config.get('MAP', 'OPTION') == "ADSBX":
|
||||||
|
getSS(self.icao, self.overlays)
|
||||||
|
#Discord
|
||||||
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
|
dis_message = (self.dis_title + " " + squawk_message)
|
||||||
|
sendDis(dis_message, self.map_file_name, self.config)
|
||||||
|
os.remove(self.map_file_name)
|
||||||
|
#Nav Modes Notifications
|
||||||
|
if self.nav_modes != None and self.last_nav_modes != None:
|
||||||
|
new_modes = []
|
||||||
|
for mode in self.nav_modes:
|
||||||
|
if mode not in self.last_nav_modes:
|
||||||
|
new_modes.append(mode)
|
||||||
|
#Discord
|
||||||
|
if new_modes != []:
|
||||||
|
modes_string = ", ".join(new_modes)
|
||||||
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
|
dis_message = (self.dis_title + " " + modes_string + " mode enabled.").strip()
|
||||||
|
getSS(self.icao, self.overlays)
|
||||||
|
sendDis(dis_message, self.map_file_name, self.config)
|
||||||
|
|
||||||
|
|
||||||
#Set Variables to compare to next check
|
#Set Variables to compare to next check
|
||||||
self.last_feeding = self.feeding
|
self.last_feeding = self.feeding
|
||||||
|
@ -359,6 +393,8 @@ class Plane:
|
||||||
self.last_below_desired_ft = self.below_desired_ft
|
self.last_below_desired_ft = self.below_desired_ft
|
||||||
self.last_longitude = self.longitude
|
self.last_longitude = self.longitude
|
||||||
self.last_latitude = self.latitude
|
self.last_latitude = self.latitude
|
||||||
|
self.last_squawk = self.squawk
|
||||||
|
self.last_nav_modes = self.nav_modes
|
||||||
|
|
||||||
|
|
||||||
if self.takeoff_time != None:
|
if self.takeoff_time != None:
|
||||||
|
|
Loading…
Reference in New Issue