Fixes new location logic, didn't have info on landing

This commit is contained in:
Jxck-S 2020-09-19 16:31:37 -04:00
parent 38b9d774eb
commit 085a667c73
1 changed files with 31 additions and 20 deletions

View File

@ -52,6 +52,8 @@ running_Count = 0
callsign = None callsign = None
takeoff_time = None takeoff_time = None
reg = None reg = None
last_latitude = None
last_longitude = None
#Begin Looping program #Begin Looping program
while True: while True:
running_Count += 1 running_Count += 1
@ -92,8 +94,6 @@ while True:
print (Fore.CYAN) print (Fore.CYAN)
if config.get('DATA', 'SOURCE') == "ADSBX": if config.get('DATA', 'SOURCE') == "ADSBX":
print("Registration: ", reg) print("Registration: ", reg)
else:
print("Registration: ", "Only shows when using ADSBX!")
print ("Callsign: ", callsign) print ("Callsign: ", callsign)
print ("On Ground: ", on_ground) print ("On Ground: ", on_ground)
print ("Latitude: ", latitude) print ("Latitude: ", latitude)
@ -119,21 +119,27 @@ while True:
#Lookup Location of coordinates #Lookup Location of coordinates
if landed or tookoff: if landed or tookoff:
if longitude != None and latitude != None: if landed and last_longitude != None and last_latitude != None:
combined = f"{last_latitude} , {last_longitude}"
has_coords = True
elif tookoff and longitude != None and latitude != None:
combined = f"{latitude} , {longitude}" combined = f"{latitude} , {longitude}"
try: has_coords = True
location = geolocator.reverse(combined)
except:
print ("Geopy API Error")
print (Fore.YELLOW)
# print ("Geopy debug: ", location.raw)
print(Style.RESET_ALL)
has_location = True
else: else:
print (Fore.RED + 'No Location') print (Fore.RED + 'No Location')
has_location = False has_location = False
invalid_Location = True invalid_Location = True
has_coords = False
print(Style.RESET_ALL) print(Style.RESET_ALL)
if has_coords:
try:
location = geolocator.reverse(combined)
except:
print ("Geopy API Error")
else:
# print (Fore.YELLOW, "Geopy debug: ", location.raw, Style.RESET_ALL)
has_location = True
@ -184,6 +190,9 @@ while True:
#Chose city town county or hamlet for location as not all are always avalible. #Chose city town county or hamlet for location as not all are always avalible.
if invalid_Location is False: if invalid_Location is False:
aera_hierarchy = city or town or county or hamlet aera_hierarchy = city or town or county or hamlet
#Set Discord Title
if config.getboolean('DISCORD', 'ENABLE'):
dis_title = icao if config.get('DISCORD', 'TITLE') == "icao" else callsign if config.get('DISCORD', 'TITLE') == "callsign" else config.get('DISCORD', 'TITLE')
#Takeoff Notifcation and Landed #Takeoff Notifcation and Landed
if tookoff: if tookoff:
@ -199,7 +208,7 @@ while True:
getSS(icao) getSS(icao)
#Discord #Discord
if config.getboolean('DISCORD', 'ENABLE'): if config.getboolean('DISCORD', 'ENABLE'):
dis_message = config.get('DISCORD', 'TITLE') + " " + tookoff_message dis_message = dis_title + " " + tookoff_message
sendDis(dis_message) sendDis(dis_message)
#PushBullet #PushBullet
if config.getboolean('PUSHBULLET', 'ENABLE'): if config.getboolean('PUSHBULLET', 'ENABLE'):
@ -231,7 +240,7 @@ while True:
getSS(icao) getSS(icao)
#Discord #Discord
if config.getboolean('DISCORD', 'ENABLE'): if config.getboolean('DISCORD', 'ENABLE'):
dis_message = config.get('DISCORD', 'TITLE') + " " + landed_message dis_message = dis_title + " " + landed_message
sendDis(dis_message) sendDis(dis_message)
#PushBullet #PushBullet
if config.getboolean('PUSHBULLET', 'ENABLE'): if config.getboolean('PUSHBULLET', 'ENABLE'):
@ -252,6 +261,8 @@ while True:
last_geo_alt_ft = geo_alt_ft last_geo_alt_ft = geo_alt_ft
last_on_ground = on_ground last_on_ground = on_ground
last_below_desired_ft = below_desired_ft last_below_desired_ft = below_desired_ft
last_longitude = longitude
last_latitude = latitude
elif failed: elif failed:
print ("Failed to connect to data source rechecking in 15s") print ("Failed to connect to data source rechecking in 15s")
@ -267,6 +278,6 @@ while True:
print (Back.MAGENTA, "--------", running_Count, "------------------------Elapsed Time- ", elapsed_calc_time, "-------------------------------------", Style.RESET_ALL) print (Back.MAGENTA, "--------", running_Count, "------------------------Elapsed Time- ", elapsed_calc_time, "-------------------------------------", Style.RESET_ALL)
print ("") print ("")
time.sleep(30) time.sleep(20)