AGL calculation, Traceback, Powerup, Route
-Use AGL to nearest airport when landing or takeoff is a unconfirmed instead of MSL, helps improve reliability in high areas. -Change airport code on image to IATA / ICAO -Better exceptions -Common Discord message method, full traceback on exits sent to Discord -Remove unneeded location code that relied on Reverse Geocode -Update TODO and refrences -Try powerup -Route lookup, not public because it breaks TOS of companies
This commit is contained in:
parent
0184eed167
commit
e76b8750bf
|
|
@ -1,5 +1,8 @@
|
||||||
def append_airport(filename, icao, airport, distance_mi):
|
def append_airport(filename, airport):
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
distance_mi = airport['distance_mi']
|
||||||
|
icao = airport['icao']
|
||||||
|
iata = airport['iata_code']
|
||||||
distance_km = distance_mi * 1.609
|
distance_km = distance_mi * 1.609
|
||||||
|
|
||||||
# create Image object with the input image
|
# create Image object with the input image
|
||||||
|
|
@ -38,9 +41,9 @@ def append_airport(filename, icao, airport, distance_mi):
|
||||||
(x, y) = (408, 740)
|
(x, y) = (408, 740)
|
||||||
text = "Nearest Airport"
|
text = "Nearest Airport"
|
||||||
draw.text((x, y), text, fill=white, font=head_font)
|
draw.text((x, y), text, fill=white, font=head_font)
|
||||||
#ICAO
|
#ICAO | IATA
|
||||||
(x, y) = (320, 765)
|
(x, y) = (320, 765)
|
||||||
text = icao
|
text = iata + " / " + icao
|
||||||
draw.text((x, y), text, fill=black, font=font)
|
draw.text((x, y), text, fill=black, font=font)
|
||||||
#Distance
|
#Distance
|
||||||
(x, y) = (432, 765)
|
(x, y) = (432, 765)
|
||||||
|
|
@ -48,7 +51,7 @@ def append_airport(filename, icao, airport, distance_mi):
|
||||||
draw.text((x, y), text, fill=black, font=font)
|
draw.text((x, y), text, fill=black, font=font)
|
||||||
#Full name
|
#Full name
|
||||||
(x, y) = (320, 783)
|
(x, y) = (320, 783)
|
||||||
text = airport[0:56]
|
text = airport['name'][0:56]
|
||||||
draw.text((x, y), text, fill=black, font=mini_font)
|
draw.text((x, y), text, fill=black, font=mini_font)
|
||||||
image.show()
|
image.show()
|
||||||
# save the edited image
|
# save the edited image
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,6 @@ python3 plane-notify
|
||||||
- General Cleanup
|
- General Cleanup
|
||||||
- Restructure project to make it proper currently random files because I didn't know how to properly structure a project before. (in progress)
|
- Restructure project to make it proper currently random files because I didn't know how to properly structure a project before. (in progress)
|
||||||
- Add requirments.txt file from pip freeze to create easy dependencies install
|
- Add requirments.txt file from pip freeze to create easy dependencies install
|
||||||
- On data loss/gain calculate AGL ft above nearest airport and use that altitude instead of just using baro/geo alt from ADS-B which is MSL.
|
- Add proper logging and service to run the program and remove excessive printing.
|
||||||
|
|
||||||
### [More Refrences/Documentation](Refrences.md)
|
### [More Refrences/Documentation](Refrences.md)
|
||||||
|
|
|
||||||
10
Refrences.md
10
Refrences.md
|
|
@ -55,6 +55,14 @@
|
||||||
|
|
||||||
- <https://pypi.org/project/tabulate/>
|
- <https://pypi.org/project/tabulate/>
|
||||||
|
|
||||||
## Nearest Airport / Airports.dat / OpenFlights
|
## Nearest Airport
|
||||||
|
|
||||||
|
- <https://www.geeksforgeeks.org/python-calculate-distance-between-two-places-using-geopy/>
|
||||||
|
|
||||||
|
### OpenFlights / airports.dat
|
||||||
|
|
||||||
- <https://openflights.org/data.html>
|
- <https://openflights.org/data.html>
|
||||||
|
|
||||||
|
### OurAirports / airports.csv / regions.csv
|
||||||
|
|
||||||
|
- <https://ourairports.com/data/>
|
||||||
|
|
|
||||||
24
__main__.py
24
__main__.py
|
|
@ -35,9 +35,8 @@ 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')
|
||||||
if main_config.getboolean('DISCORD', 'ENABLE'):
|
if main_config.getboolean('DISCORD', 'ENABLE'):
|
||||||
from discord_webhook import DiscordWebhook
|
from defDiscord import sendDis
|
||||||
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Started")))
|
sendDis("Started", main_config)
|
||||||
webhook.execute()
|
|
||||||
try:
|
try:
|
||||||
print("Source is set to", source)
|
print("Source is set to", source)
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -75,7 +74,7 @@ try:
|
||||||
elif api_version == 1:
|
elif api_version == 1:
|
||||||
icao_key = 'icao'
|
icao_key = 'icao'
|
||||||
else:
|
else:
|
||||||
raise Exception("Invalid API Version")
|
raise ValueError("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:
|
||||||
|
|
@ -124,8 +123,8 @@ try:
|
||||||
source = "OPENS"
|
source = "OPENS"
|
||||||
failed_count = 0
|
failed_count = 0
|
||||||
if main_config.getboolean('DISCORD', 'ENABLE'):
|
if main_config.getboolean('DISCORD', 'ENABLE'):
|
||||||
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Failed over to " + source)))
|
from defDiscord import sendDis
|
||||||
webhook.execute()
|
sendDis(str("Failed over to " + source), main_config)
|
||||||
elapsed_calc_time = time.time() - start_time
|
elapsed_calc_time = time.time() - start_time
|
||||||
datetime_tz = datetime.now(tz)
|
datetime_tz = datetime.now(tz)
|
||||||
footer = "-------- " + str(running_Count) + " -------- " + str(datetime_tz.strftime("%I:%M:%S %p")) + " ------------------------Elapsed Time- " + str(round(elapsed_calc_time, 3)) + " -------------------------------------"
|
footer = "-------- " + str(running_Count) + " -------- " + str(datetime_tz.strftime("%I:%M:%S %p")) + " ------------------------Elapsed Time- " + str(round(elapsed_calc_time, 3)) + " -------------------------------------"
|
||||||
|
|
@ -145,11 +144,10 @@ try:
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
print(e)
|
print(e)
|
||||||
if main_config.getboolean('DISCORD', 'ENABLE'):
|
if main_config.getboolean('DISCORD', 'ENABLE'):
|
||||||
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Manual Exit: " + str(e) )))
|
from defDiscord import sendDis
|
||||||
webhook.execute()
|
sendDis(str("Manual Exit: " + str(e)), main_config)
|
||||||
except BaseException as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
print(traceback.format_exc())
|
|
||||||
if main_config.getboolean('DISCORD', 'ENABLE'):
|
if main_config.getboolean('DISCORD', 'ENABLE'):
|
||||||
webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Error Exiting: " + str(e) )))
|
from defDiscord import sendDis
|
||||||
webhook.execute()
|
sendDis(str("Error Exiting: " + str(traceback.format_exc())), main_config)
|
||||||
|
raise e
|
||||||
|
|
@ -15,7 +15,7 @@ API_KEY = apikey
|
||||||
API_VERSION = 1
|
API_VERSION = 1
|
||||||
#ADSBX API Proxy V2, https://gitlab.com/jjwiseman/adsbx-api-proxy
|
#ADSBX API Proxy V2, https://gitlab.com/jjwiseman/adsbx-api-proxy
|
||||||
ENABLE_PROXY = FALSE
|
ENABLE_PROXY = FALSE
|
||||||
PROXY_HOST = N/A
|
PROXY_HOST =
|
||||||
|
|
||||||
#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
|
||||||
|
|
@ -27,8 +27,8 @@ PASSWORD = None
|
||||||
#API KEY for Google Static Maps only if you using this on any of the planes.
|
#API KEY for Google Static Maps only if you using this on any of the planes.
|
||||||
API_KEY = googleapikey
|
API_KEY = googleapikey
|
||||||
|
|
||||||
#Used for failover messages
|
#Used for failover messages and program exits notifcation
|
||||||
[DISCORD]
|
[DISCORD]
|
||||||
ENABLE = FALSE
|
ENABLE = FALSE
|
||||||
|
USERNAME = usernamehere
|
||||||
URL = webhookurl
|
URL = webhookurl
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@ def pullADSBX(planes):
|
||||||
elif api_version == 2:
|
elif api_version == 2:
|
||||||
url = "https://adsbexchange.com/api/aircraft/v2/all"
|
url = "https://adsbexchange.com/api/aircraft/v2/all"
|
||||||
else:
|
else:
|
||||||
raise Exception("No API Version set")
|
raise ValueError("No API Version set")
|
||||||
else:
|
else:
|
||||||
if main_config.has_option('ADSBX', 'PROXY_HOST'):
|
if main_config.has_option('ADSBX', 'PROXY_HOST'):
|
||||||
url = "http://" + main_config.get('ADSBX', 'PROXY_HOST') + ":8000/api/aircraft/v2/all"
|
url = "http://" + main_config.get('ADSBX', 'PROXY_HOST') + ":8000/api/aircraft/v2/all"
|
||||||
else:
|
else:
|
||||||
raise BaseException("Proxy enabled but no host")
|
raise ValueError("Proxy enabled but no host")
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'api-auth': main_config.get('ADSBX', 'API_KEY'),
|
'api-auth': main_config.get('ADSBX', 'API_KEY'),
|
||||||
|
|
@ -37,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, urllib3.exceptions.ProtocolError, ValueError) as error_message:
|
except (IncompleteRead, ConnectionResetError, urllib3.Exceptions, ValueError) as error_message:
|
||||||
print("Connection Error")
|
print("Connection Error")
|
||||||
print(error_message)
|
print(error_message)
|
||||||
failed = True
|
failed = True
|
||||||
|
|
@ -72,7 +72,7 @@ def pullADSBX(planes):
|
||||||
if failed is False:
|
if failed is False:
|
||||||
try:
|
try:
|
||||||
if data['msg'] != "No error":
|
if data['msg'] != "No error":
|
||||||
raise Exception("Error from ADSBX: msg = ", data['msg'])
|
raise ValueError("Error from ADSBX: msg = ", data['msg'])
|
||||||
failed = True
|
failed = True
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,3 @@
|
||||||
#https://www.geeksforgeeks.org/python-calculate-distance-between-two-places-using-geopy/
|
|
||||||
#https://openflights.org/data.html
|
|
||||||
|
|
||||||
#OLD Airport lookup
|
|
||||||
# def getClosestAirport(latitude, longitude):
|
|
||||||
# import csv
|
|
||||||
# from geopy.distance import geodesic
|
|
||||||
# plane = (latitude, longitude)
|
|
||||||
# header = ["id", "name", "city", "country", "iata", "icao", "lat", "lng", "alt", "tz", "dst", "tz_db", "type", "source"]
|
|
||||||
# with open('airports.dat', encoding='utf-8') as airport_dat:
|
|
||||||
# airport_dat_reader = csv.DictReader(filter(lambda row: row[0]!='#', airport_dat), header)
|
|
||||||
# for airport in airport_dat_reader:
|
|
||||||
# airport_coord = float(airport['lat']), float(airport['lng'])
|
|
||||||
# airport_dist = float((geodesic(plane, airport_coord).mi))
|
|
||||||
# if "closest_airport_dict" not in locals():
|
|
||||||
# closest_airport_dict = airport
|
|
||||||
# closest_airport_dist = airport_dist
|
|
||||||
# elif airport_dist < closest_airport_dist:
|
|
||||||
# closest_airport_dict = airport
|
|
||||||
# closest_airport_dist = airport_dist
|
|
||||||
# closest_airport_dict['distance'] = closest_airport_dist
|
|
||||||
# print("Closest Airport:", closest_airport_dict['icao'], closest_airport_dict['name'], closest_airport_dist, "Miles Away")
|
|
||||||
# return closest_airport_dict
|
|
||||||
def getClosestAirport(latitude, longitude, allowed_types):
|
def getClosestAirport(latitude, longitude, allowed_types):
|
||||||
import csv
|
import csv
|
||||||
from geopy.distance import geodesic
|
from geopy.distance import geodesic
|
||||||
|
|
@ -39,7 +16,7 @@ def getClosestAirport(latitude, longitude, allowed_types):
|
||||||
closest_airport_dist = airport_dist
|
closest_airport_dist = airport_dist
|
||||||
closest_airport_dict['distance_mi'] = closest_airport_dist
|
closest_airport_dict['distance_mi'] = closest_airport_dist
|
||||||
#Convert indent key to icao key as its labeled icao in other places not ident
|
#Convert indent key to icao key as its labeled icao in other places not ident
|
||||||
closest_airport_dict['icao'] = closest_airport_dict.pop('ident')
|
closest_airport_dict['icao'] = closest_airport_dict.pop('gps_code')
|
||||||
#Get full region/state name from iso region name
|
#Get full region/state name from iso region name
|
||||||
with open('regions.csv', 'r', encoding='utf-8') as regions_csv:
|
with open('regions.csv', 'r', encoding='utf-8') as regions_csv:
|
||||||
regions_csv = csv.DictReader(filter(lambda row: row[0]!='#', regions_csv))
|
regions_csv = csv.DictReader(filter(lambda row: row[0]!='#', regions_csv))
|
||||||
|
|
@ -47,3 +24,14 @@ def getClosestAirport(latitude, longitude, allowed_types):
|
||||||
if region['code'] == closest_airport_dict['iso_region']:
|
if region['code'] == closest_airport_dict['iso_region']:
|
||||||
closest_airport_dict['region'] = region['name']
|
closest_airport_dict['region'] = region['name']
|
||||||
return closest_airport_dict
|
return closest_airport_dict
|
||||||
|
def get_airport_by_icao(icao):
|
||||||
|
import csv
|
||||||
|
with open('airports.csv', 'r', encoding='utf-8') as airport_csv:
|
||||||
|
airport_csv_reader = csv.DictReader(filter(lambda row: row[0]!='#', airport_csv))
|
||||||
|
for airport in airport_csv_reader:
|
||||||
|
if airport['gps_code'] == icao:
|
||||||
|
matching_airport = airport
|
||||||
|
#Convert indent key to icao key as its labeled icao in other places not ident
|
||||||
|
matching_airport['icao'] = matching_airport.pop('gps_code')
|
||||||
|
break
|
||||||
|
return matching_airport
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
|
||||||
def sendDis(message, config, image_name = None):
|
def sendDis(message, config, image_name = None):
|
||||||
|
import requests
|
||||||
from discord_webhook import DiscordWebhook
|
from discord_webhook import DiscordWebhook
|
||||||
webhook = DiscordWebhook(url=config.get('DISCORD', 'URL'), content=message, username=config.get('DISCORD', 'USERNAME'))
|
webhook = DiscordWebhook(url=config.get('DISCORD', 'URL'), content=message[0:1999], username=config.get('DISCORD', 'USERNAME'))
|
||||||
|
|
||||||
if image_name != None:
|
if image_name != None:
|
||||||
with open(image_name, "rb") as f:
|
with open(image_name, "rb") as f:
|
||||||
webhook.add_file(file=f.read(), filename='map.png')
|
webhook.add_file(file=f.read(), filename='map.png')
|
||||||
|
try:
|
||||||
webhook.execute()
|
webhook.execute()
|
||||||
|
except requests.Exceptions:
|
||||||
|
pass
|
||||||
160
planeClass.py
160
planeClass.py
|
|
@ -25,6 +25,18 @@ class Plane:
|
||||||
self.squawks = [None, None, None, None]
|
self.squawks = [None, None, None, None]
|
||||||
self.nav_modes = None
|
self.nav_modes = None
|
||||||
self.last_nav_modes = None
|
self.last_nav_modes = None
|
||||||
|
self.recheck_to = None
|
||||||
|
self.speed = None
|
||||||
|
self.nearest_airport_dict = None
|
||||||
|
#Setup Tweepy
|
||||||
|
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||||
|
from defTweet import tweepysetup
|
||||||
|
self.tweet_api = tweepysetup(self.config)
|
||||||
|
#Setup PushBullet
|
||||||
|
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||||
|
from pushbullet import Pushbullet
|
||||||
|
self.pb = Pushbullet(self.config['PUSHBULLET']['API_KEY'])
|
||||||
|
self.pb_channel = self.pb.get_channel(self.config.get('PUSHBULLET', 'CHANNEL_TAG'))
|
||||||
def getICAO(self):
|
def getICAO(self):
|
||||||
return self.icao
|
return self.icao
|
||||||
def run_OPENS(self, ac_dict):
|
def run_OPENS(self, ac_dict):
|
||||||
|
|
@ -81,7 +93,7 @@ class Plane:
|
||||||
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:
|
||||||
self.__dict__.update({'icao' : ac_dict['hex'].upper(), 'reg' : ac_dict['r'], 'latitude' : float(ac_dict['lat']), 'longitude' : float(ac_dict['lon'])})
|
self.__dict__.update({'icao' : ac_dict['hex'].upper(), 'reg' : ac_dict['r'], 'latitude' : float(ac_dict['lat']), 'longitude' : float(ac_dict['lon']), 'type' : ac_dict['t'], 'speed': ac_dict['gs']})
|
||||||
if ac_dict['alt_baro'] != "ground":
|
if ac_dict['alt_baro'] != "ground":
|
||||||
self.alt_ft = int(ac_dict['alt_baro'])
|
self.alt_ft = int(ac_dict['alt_baro'])
|
||||||
self.on_ground = False
|
self.on_ground = False
|
||||||
|
|
@ -129,7 +141,6 @@ class Plane:
|
||||||
elif type == "foot":
|
elif type == "foot":
|
||||||
header = "----------------------------------------------------------------------------------------------------"
|
header = "----------------------------------------------------------------------------------------------------"
|
||||||
print(Back.MAGENTA + header[0:100] + Style.RESET_ALL)
|
print(Back.MAGENTA + header[0:100] + Style.RESET_ALL)
|
||||||
|
|
||||||
def get_time_since(self, last_contact):
|
def get_time_since(self, last_contact):
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
if last_contact != None:
|
if last_contact != None:
|
||||||
|
|
@ -138,6 +149,10 @@ class Plane:
|
||||||
else:
|
else:
|
||||||
time_since_contact = None
|
time_since_contact = None
|
||||||
return time_since_contact
|
return time_since_contact
|
||||||
|
def time_since(self, start_time):
|
||||||
|
import time
|
||||||
|
elapsed_time = time.time() - start_time
|
||||||
|
return elapsed_time
|
||||||
def run_empty(self):
|
def run_empty(self):
|
||||||
self.printheader("head")
|
self.printheader("head")
|
||||||
self.feeding = False
|
self.feeding = False
|
||||||
|
|
@ -154,6 +169,15 @@ class Plane:
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
from AppendAirport import append_airport
|
from AppendAirport import append_airport
|
||||||
from defAirport import getClosestAirport
|
from defAirport import getClosestAirport
|
||||||
|
|
||||||
|
#Propritary
|
||||||
|
ENABLE_ROUTE_LOOKUP = False
|
||||||
|
if ENABLE_ROUTE_LOOKUP:
|
||||||
|
from lookup_route import lookup_route
|
||||||
|
else:
|
||||||
|
#Dead Place function
|
||||||
|
def lookup_route(*args):
|
||||||
|
return None
|
||||||
if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
if self.config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
||||||
from defMap import getMap
|
from defMap import getMap
|
||||||
elif self.config.get('MAP', 'OPTION') == "ADSBX":
|
elif self.config.get('MAP', 'OPTION') == "ADSBX":
|
||||||
|
|
@ -166,16 +190,6 @@ class Plane:
|
||||||
raise ValueError("Map option not set correctly in this planes conf")
|
raise ValueError("Map option not set correctly in this planes conf")
|
||||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
from defDiscord import sendDis
|
from defDiscord import sendDis
|
||||||
#Setup Tweepy
|
|
||||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
|
||||||
from defTweet import tweepysetup
|
|
||||||
self.tweet_api = tweepysetup(self.config)
|
|
||||||
#Setup PushBullet
|
|
||||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
|
||||||
from pushbullet import Pushbullet
|
|
||||||
self.pb = Pushbullet(self.config['PUSHBULLET']['API_KEY'])
|
|
||||||
self.pb_channel = self.pb.get_channel(self.config.get('PUSHBULLET', 'CHANNEL_TAG'))
|
|
||||||
|
|
||||||
if self.feeding == False:
|
if self.feeding == False:
|
||||||
time_since_contact = self.get_time_since(self.last_contact)
|
time_since_contact = self.get_time_since(self.last_contact)
|
||||||
output = [
|
output = [
|
||||||
|
|
@ -204,7 +218,7 @@ class Plane:
|
||||||
print(tabulate(output, [], 'fancy_grid'))
|
print(tabulate(output, [], 'fancy_grid'))
|
||||||
|
|
||||||
#Check if below desire ft
|
#Check if below desire ft
|
||||||
desired_ft = 10000
|
desired_ft = 15000
|
||||||
if self.alt_ft is None or self.alt_ft > desired_ft:
|
if self.alt_ft is None or self.alt_ft > desired_ft:
|
||||||
self.below_desired_ft = False
|
self.below_desired_ft = False
|
||||||
elif self.alt_ft < desired_ft:
|
elif self.alt_ft < desired_ft:
|
||||||
|
|
@ -214,71 +228,77 @@ 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.type_header = "Took off from "
|
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:
|
||||||
|
nearest_airport_dict = getClosestAirport(self.latitude, self.longitude, self.config.get("AIRPORT", "TYPES"))
|
||||||
|
alt_above_airport = (self.alt_ft - int(nearest_airport_dict['elevation_ft']))
|
||||||
|
print(f"AGL nearest airport: {alt_above_airport}")
|
||||||
|
if alt_above_airport <= 10000:
|
||||||
|
self.nearest_airport_dict = nearest_airport_dict
|
||||||
self.tookoff = True
|
self.tookoff = True
|
||||||
self.trigger_type = "data acquisition"
|
self.trigger_type = "data acquisition"
|
||||||
self.type_header = "Took off near "
|
type_header = "Took off near"
|
||||||
else:
|
else:
|
||||||
self.tookoff = False
|
self.tookoff = False
|
||||||
else:
|
else:
|
||||||
self.tookoff = False
|
self.tookoff = False
|
||||||
|
|
||||||
#self.tookoff = bool(self.below_desired_ft and self.on_ground is False and ((self.last_feeding is False and self.feeding) or (self.last_on_ground)))
|
|
||||||
#print ("Tookoff Just Now:", self.tookoff)
|
|
||||||
|
|
||||||
|
|
||||||
#Check if Landed
|
#Check if Landed
|
||||||
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.type_header = "Landed in "
|
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.below_desired_ft and self.last_feeding and self.feeding is False and self.last_on_ground is False:
|
||||||
print("Near landing conditions, if contiuned data loss for 5 mins, landing true")
|
nearest_airport_dict = getClosestAirport(self.latitude, self.longitude, self.config.get("AIRPORT", "TYPES"))
|
||||||
|
alt_above_airport = (self.alt_ft - int(nearest_airport_dict['elevation_ft']))
|
||||||
|
print(f"AGL nearest airport: {alt_above_airport}")
|
||||||
|
if alt_above_airport <= 10000:
|
||||||
self.landing_plausible = True
|
self.landing_plausible = True
|
||||||
|
self.nearest_airport_dict = nearest_airport_dict
|
||||||
|
print("Near landing conditions, if contiuned data loss for 5 mins, landing true")
|
||||||
|
|
||||||
elif self.landing_plausible and self.feeding is False and time_since_contact.seconds >= 300:
|
elif self.landing_plausible and self.feeding is False and time_since_contact.seconds >= 300:
|
||||||
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.type_header = "Landed near "
|
type_header = "Landed near"
|
||||||
else:
|
else:
|
||||||
self.landed = False
|
self.landed = False
|
||||||
|
|
||||||
#self.landed = bool(self.last_below_desired_ft and ((self.last_feeding and self.feeding is False and self.last_on_ground is False) or (self.on_ground and self.last_on_ground is False)))
|
|
||||||
#print ("Landed Just Now:", self.landed)
|
|
||||||
if self.landed:
|
if self.landed:
|
||||||
print ("Landed by", self.trigger_type)
|
print ("Landed by", self.trigger_type)
|
||||||
if self.tookoff:
|
if self.tookoff:
|
||||||
print("Tookoff by", self.trigger_type)
|
print("Tookoff by", self.trigger_type)
|
||||||
#Find nearest airport, and location
|
#Find nearest airport, and location
|
||||||
if self.landed or self.tookoff:
|
if self.landed or self.tookoff:
|
||||||
if self.trigger_type == "now on ground" or "data acquisition" and self.longitude != None and self.latitude != None:
|
if self.nearest_airport_dict != None:
|
||||||
|
nearest_airport_dict = self.nearest_airport_dict
|
||||||
|
self.nearest_airport_dict = None
|
||||||
|
elif self.trigger_type in ["now on ground", "data acquisition", "data loss"]:
|
||||||
nearest_airport_dict = getClosestAirport(self.latitude, self.longitude, self.config.get("AIRPORT", "TYPES"))
|
nearest_airport_dict = getClosestAirport(self.latitude, self.longitude, self.config.get("AIRPORT", "TYPES"))
|
||||||
has_coords = True
|
elif self.trigger_type == "no longer on ground":
|
||||||
elif self.trigger_type == "data loss" or "no longer on ground" and self.last_longitude != None and self.last_latitude != None:
|
|
||||||
nearest_airport_dict = getClosestAirport(self.last_latitude, self.last_longitude, self.config.get("AIRPORT", "TYPES"))
|
nearest_airport_dict = getClosestAirport(self.last_latitude, self.last_longitude, self.config.get("AIRPORT", "TYPES"))
|
||||||
has_coords = True
|
|
||||||
else:
|
|
||||||
print (Fore.RED + 'No Location, No coordinates')
|
|
||||||
has_coords = False
|
|
||||||
print(Style.RESET_ALL)
|
|
||||||
if has_coords:
|
|
||||||
#Convert dictionary keys to sep variables
|
#Convert dictionary keys to sep variables
|
||||||
country_code = nearest_airport_dict['iso_country']
|
country_code = nearest_airport_dict['iso_country']
|
||||||
state = nearest_airport_dict['region'].strip()
|
state = nearest_airport_dict['region'].strip()
|
||||||
municipality = nearest_airport_dict['municipality'].strip()
|
municipality = nearest_airport_dict['municipality'].strip()
|
||||||
|
if municipality == "" or state == "" or municipality == state:
|
||||||
|
if municipality != "":
|
||||||
|
area = municipality
|
||||||
|
elif state != "":
|
||||||
|
area = state
|
||||||
|
else:
|
||||||
|
area = ""
|
||||||
|
else:
|
||||||
|
area = f"{municipality}, {state}, "
|
||||||
|
location_string = (area + country_code)
|
||||||
print (Fore.GREEN)
|
print (Fore.GREEN)
|
||||||
print ("Country Code: ", country_code)
|
print ("Country Code: ", country_code)
|
||||||
print ("State: ", state)
|
print ("State: ", state)
|
||||||
print ("Municipality: ", municipality)
|
print ("Municipality: ", municipality)
|
||||||
print(Style.RESET_ALL)
|
print(Style.RESET_ALL)
|
||||||
else:
|
|
||||||
print (Fore.RED)
|
|
||||||
print ("Invalid Location")
|
|
||||||
print(Style.RESET_ALL)
|
|
||||||
title_switch = {
|
title_switch = {
|
||||||
"reg": self.reg,
|
"reg": self.reg,
|
||||||
"callsign": self.callsign,
|
"callsign": self.callsign,
|
||||||
|
|
@ -286,46 +306,46 @@ class Plane:
|
||||||
}
|
}
|
||||||
#Set Discord Title
|
#Set Discord Title
|
||||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
self.dis_title = (title_switch.get(self.config.get('DISCORD', 'TITLE')) or "NA") if self.config.get('DISCORD', 'TITLE') in title_switch.keys() else self.config.get('DISCORD', 'TITLE')
|
self.dis_title = (title_switch.get(self.config.get('DISCORD', 'TITLE')) or "NA").strip() if self.config.get('DISCORD', 'TITLE') in title_switch.keys() else self.config.get('DISCORD', 'TITLE')
|
||||||
#Set Twitter Title
|
#Set Twitter Title
|
||||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||||
self.twitter_title = (title_switch.get(self.config.get('TWITTER', 'TITLE')) or "NA") if self.config.get('TWITTER', 'TITLE') in title_switch.keys() else self.config.get('TWITTER', 'TITLE')
|
self.twitter_title = (title_switch.get(self.config.get('TWITTER', 'TITLE')) or "NA") if self.config.get('TWITTER', 'TITLE') in title_switch.keys() else self.config.get('TWITTER', 'TITLE')
|
||||||
#Takeoff and Land Notification
|
#Takeoff and Land Notification
|
||||||
if self.tookoff or self.landed:
|
if self.tookoff or self.landed:
|
||||||
|
route_to = None
|
||||||
if self.tookoff:
|
if self.tookoff:
|
||||||
self.takeoff_time = time.time()
|
self.takeoff_time = time.time()
|
||||||
self.landed_time_msg = None
|
landed_time_msg = None
|
||||||
|
#Route Lookup | Proprietary
|
||||||
|
if ENABLE_ROUTE_LOOKUP:
|
||||||
|
route_to = lookup_route(self.reg, (self.latitude, self.longitude), self.type, self.alt_ft)
|
||||||
|
if route_to == None:
|
||||||
|
self.recheck_to = True
|
||||||
elif self.landed and self.takeoff_time != None:
|
elif self.landed and self.takeoff_time != None:
|
||||||
self.landed_time = time.time() - self.takeoff_time
|
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))
|
strftime_splitter = "-"
|
||||||
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))
|
strftime_splitter = "#"
|
||||||
self.landed_time_msg = self.landed_time_msg.replace("0 Hours : ", "")
|
landed_time_msg = time.strftime(f"Apx. flt. time %{strftime_splitter}H Hours : %{strftime_splitter}M Mins. ", time.gmtime(landed_time))
|
||||||
|
landed_time_msg = landed_time_msg.replace("0 Hours : ", "")
|
||||||
self.takeoff_time = None
|
self.takeoff_time = None
|
||||||
self.landed_time = None
|
|
||||||
elif self.landed:
|
elif self.landed:
|
||||||
self.landed_time_msg = None
|
landed_time_msg = None
|
||||||
if has_coords:
|
message = (f"{type_header} {location_string}.") + ("" if route_to is None else f" {route_to}.") + ((f" {landed_time_msg}") if landed_time_msg != None else "")
|
||||||
message = (self.type_header + (((municipality + ", " + state) if municipality != "" else "" ) if municipality != state else state) + ", " + country_code + ".") + ((" " + self.landed_time_msg) if self.landed_time_msg != None else "")
|
|
||||||
else:
|
|
||||||
message = ("Landed" + ((" " + self.landed_time_msg) if self.landed_time_msg != None else "") if self.landed else "Tookoff" if self.tookoff else "")
|
|
||||||
print (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((municipality + ", " + state + ", " + country_code), self.map_file_name)
|
getMap((municipality + ", " + state + ", " + country_code), self.map_file_name)
|
||||||
elif self.config.get('MAP', 'OPTION') == "ADSBX":
|
elif self.config.get('MAP', 'OPTION') == "ADSBX":
|
||||||
getSS(self.icao, self.overlays)
|
getSS(self.icao, self.overlays)
|
||||||
if nearest_airport_dict != None:
|
append_airport(self.map_file_name, nearest_airport_dict)
|
||||||
append_airport(self.map_file_name, nearest_airport_dict['icao'], nearest_airport_dict['name'], nearest_airport_dict['distance_mi'])
|
#airport_string = nearest_airport_dict['icao'] + ", " + nearest_airport_dict["name"]
|
||||||
airport_string = nearest_airport_dict['icao'] + ", " + nearest_airport_dict["name"]
|
|
||||||
else:
|
else:
|
||||||
airport_string = ""
|
raise ValueError("Map option not set correctly in this planes conf")
|
||||||
else:
|
|
||||||
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 + " " + message + " " + airport_string).strip()
|
dis_message = f"{self.dis_title} {message}".strip()
|
||||||
sendDis(dis_message, self.config, self.map_file_name)
|
sendDis(dis_message, self.config, self.map_file_name)
|
||||||
#PushBullet
|
#PushBullet
|
||||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||||
|
|
@ -336,11 +356,22 @@ class Plane:
|
||||||
#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 or "NA") + " On Ground: " + str(self.on_ground) + " Alt: " + str(self.alt_ft) + " Last Contact: " + str(time_since_contact) + " Trigger: " + self.trigger_type
|
alt_text = f"Reg: {self.reg} On Ground: {str(self.on_ground)} Alt: {str(self.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 + " " + 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 + " " + tookoff_message).strip())
|
|
||||||
os.remove(self.map_file_name)
|
os.remove(self.map_file_name)
|
||||||
|
#To Location
|
||||||
|
if self.recheck_to and self.time_since(self.takeoff_time) > 60:
|
||||||
|
self.recheck_to = False
|
||||||
|
route_to = lookup_route(self.reg, (self.latitude, self.longitude), self.type, self.alt_ft)
|
||||||
|
if route_to != None:
|
||||||
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
|
dis_message = (self.dis_title + route_to).strip()
|
||||||
|
sendDis(dis_message, self.config)
|
||||||
|
#Twitter
|
||||||
|
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||||
|
tweet = self.tweet_api.user_timeline(count = 1)[0]
|
||||||
|
self.tweet_api.update_status(status = f"{self.twitter_title} {route_to}".strip(), in_reply_to_status_id = tweet.id)
|
||||||
|
|
||||||
#Squawks
|
#Squawks
|
||||||
squawks =[("7500", "Hijacking"), ("7600", "Radio Failure"), ("7700", "Emergency")]
|
squawks =[("7500", "Hijacking"), ("7600", "Radio Failure"), ("7700", "Emergency")]
|
||||||
|
|
@ -374,6 +405,11 @@ class Plane:
|
||||||
sendDis((dis_message + ", Sel Alt. " + str(self.nav_altitude) + ", Current Alt. " + str(self.alt_ft)), self.config)
|
sendDis((dis_message + ", Sel Alt. " + str(self.nav_altitude) + ", Current Alt. " + str(self.alt_ft)), self.config)
|
||||||
else:
|
else:
|
||||||
sendDis(dis_message, self.config)
|
sendDis(dis_message, self.config)
|
||||||
|
#Power Up
|
||||||
|
if self.last_feeding == False and self.speed == 0 and self.on_ground:
|
||||||
|
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
|
dis_message = (self.dis_title + "Powered Up").strip()
|
||||||
|
sendDis(dis_message, self.config)
|
||||||
|
|
||||||
|
|
||||||
#Set Variables to compare to next check
|
#Set Variables to compare to next check
|
||||||
|
|
@ -387,7 +423,7 @@ class Plane:
|
||||||
|
|
||||||
|
|
||||||
if self.takeoff_time != None:
|
if self.takeoff_time != None:
|
||||||
self.elapsed_time = time.time() - self.takeoff_time
|
elapsed_time = self.time_since(self.takeoff_time)
|
||||||
self.time_since_tk = time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(self.elapsed_time))
|
time_since_tk = time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(elapsed_time))
|
||||||
print(self.time_since_tk)
|
print(time_since_tk)
|
||||||
self.printheader("foot")
|
self.printheader("foot")
|
||||||
Loading…
Reference in New Issue