Change Name and changes

This commit is contained in:
Jxck-S 2020-06-08 13:53:37 -04:00
parent 9bc1ec3cfd
commit b9d2254162
1 changed files with 50 additions and 51 deletions

View File

@ -6,24 +6,28 @@ import time
from colorama import Fore, Back, Style from colorama import Fore, Back, Style
#Various imports for output #Various imports for output
from pushbullet import Pushbullet from pushbullet import Pushbullet
pb = Pushbullet("***REMOVED***") pb = Pushbullet("")
geolocator = Nominatim(user_agent="OpenSkyBot", timeout=5) geolocator = Nominatim(user_agent="OpenSkyBot", timeout=5)
api = OpenSkyApi("", "") api = OpenSkyApi("", "")
#Set Plane ICAO #Set Plane ICAO
TRACK_PLANE = 'a4c79b' TRACK_PLANE = 'A833535AF'
#Pre Set Variables #Pre Set Variables
geo_altitude = None geo_altitude = None
feeding = None feeding = None
last_feeding = None last_feeding = None
last_on_ground = None
on_ground = None
invalid_Location = None
longitude = None
latitude = None
running_Count = 0
#Begin Looping program #Begin Looping program
while True: while True:
#Preset reseting variables running_Count += 1
invalid_Location = None print (Back.MAGENTA, "--------", running_Count, "-------------------------------------------------------------", Style.RESET_ALL)
longitude = None
latitude = None
#Get API States for Plane #Get API States for Plane
planeData = api.get_states(icao24=TRACK_PLANE) planeData = api.get_states(icao24=TRACK_PLANE)
print (Fore.YELLOW) print (Fore.YELLOW)
@ -31,7 +35,7 @@ while True:
print(Style.RESET_ALL) print(Style.RESET_ALL)
#Pull Variables from planeData #Pull Variables from planeData
if (planeData != None): if planeData != None:
for dataStates in planeData.states: for dataStates in planeData.states:
longitude = (dataStates.longitude) longitude = (dataStates.longitude)
latitude = (dataStates.latitude) latitude = (dataStates.latitude)
@ -46,7 +50,7 @@ while True:
#Lookup Location of coordinates #Lookup Location of coordinates
if not((longitude == None) and (latitude == None)): if longitude != None and latitude != None:
combined = f"{latitude}, {longitude}" combined = f"{latitude}, {longitude}"
location = geolocator.reverse(combined) location = geolocator.reverse(combined)
@ -55,10 +59,10 @@ while True:
print(Style.RESET_ALL) print(Style.RESET_ALL)
feeding = True feeding = True
else: else:
print (Fore.RED + 'Not Feeding Location') print (Fore.RED + 'Not Feeding')
feeding = False feeding = False
print(Style.RESET_ALL) print(Style.RESET_ALL)
print ("Feeding: ", feeding)
#Figure if valid location, valid being geopy finds a location #Figure if valid location, valid being geopy finds a location
if feeding: if feeding:
try: try:
@ -68,74 +72,69 @@ while True:
geoError = None geoError = None
else: else:
invalid_Location = True invalid_Location = True
if invalid_Location:
print (Fore.RED)
print ("Invalid Location: ", invalid_Location) print ("Invalid Location: ", invalid_Location)
print (geoError)
print ("Likely Over Water or Invalid Location") if invalid_Location:
print(Style.RESET_ALL) print (Fore.RED)
print (geoError)
print ("Likely Over Water or Invalid Location")
print(Style.RESET_ALL)
#Convert Full address to sep variables #Convert Full address to sep variables only if Valid Location
elif feeding: elif invalid_location is False:
address = location.raw['address'] address = location.raw['address']
country = address.get('country', '') country = address.get('country', '')
state = address.get('state', '') state = address.get('state', '')
county = address.get('county', '') county = address.get('county', '')
city = address.get('city', '') city = address.get('city', '')
print (Fore.YELLOW) # print (Fore.YELLOW)
print ("Address Fields debug: ", address) # print ("Address Fields debug: ", address)
print(Style.RESET_ALL) # print(Style.RESET_ALL)
print (Fore.GREEN) print (Fore.GREEN)
print("Entire Address: ", location.address) print("Entire Address: ", location.address)
print () print ()
print ("Country: ", country) print ("Country: ", country)
print ("State: ", state) print ("State: ", state)
print ("City: ", city) print ("City: ", city)
print ("County: ", county) print ("County: ", county)
print(Style.RESET_ALL) print(Style.RESET_ALL)
#Check if tookoff #Check if tookoff
tookoff = bool(last_feeding is False and feeding and on_ground is False and invalid_Location is False and geo_altitude < 10000) tookoff = bool(last_feeding is False and feeding and on_ground is False and invalid_Location is False and geo_altitude < 10000)
print ("Tookoff Just Now:", tookoff) print ("Tookoff Just Now:", tookoff)
#Check if Landed #Check if Landed
landed = bool((last_feeding and feeding is False and invalid_Location is False and last_geo_altitude < 10000) or (on_ground and last_on_ground is False)) landed = bool((last_feeding and feeding is False and invalid_Location is False and last_geo_altitude < 10000) or (on_ground and last_on_ground is False))
print ("Landed Just Now:", landed) print ("Landed Just Now:", landed)
#Takeoff Notifcation and Landed #Takeoff Notifcation and Landed
if tookoff: if tookoff:
tookoff_message = ("Just took off from" + " " + city + ", " + state + ", " + country) tookoff_message = ("Just took off from" + " " + (city or county) + ", " + state + ", " + country)
print (tookoff_message) print (tookoff_message)
push = pb.push_note("Elon's Jet", tookoff_message) push = pb.push_note("Elon's Jet", tookoff_message)
if landed: if landed:
landed_message = ("Landed just now at" + " " + city + ", " + state + ", " + country) landed_message = ("Landed just now at" + " " + (city or county) + ", " + state + ", " + country)
print (landed_message) print (landed_message)
push = pb.push_note("Elon's Jet", landed_message) push = pb.push_note("Elon's Jet", landed_message)
#Set Variables to compare to next check
last_feeding = feeding last_feeding = feeding
last_geo_altitude = geo_altitude last_geo_altitude = geo_altitude
last_on_ground = on_ground last_on_ground = on_ground
else: else:
print ("Rechecking OpenSky") print ("Rechecking OpenSky")
planeDataMSG = str(planeData) planeDataMSG = str(planeData)
push = pb.push_note("Rechecking OpenSky, OpenSky Debug->", planeDataMSG) push = pb.push_note("Rechecking OpenSky, OpenSky Debug->", planeDataMSG)
print (Back.MAGENTA, "--------------------------------------------------------------------") print (Back.MAGENTA, "--------", running_Count, "-------------------------------------------------------------", Style.RESET_ALL)
print(Style.RESET_ALL) print ("")
time.sleep(15) time.sleep(15)