Backing up old changes from PC- 8
This commit is contained in:
parent
f3bb7b6af6
commit
485f8814cc
|
@ -6,24 +6,21 @@ geolocator = Nominatim(user_agent="*", timeout=5)
|
|||
import json
|
||||
import time
|
||||
from colorama import Fore, Back, Style
|
||||
import datetime
|
||||
from OpenSkySetup import pullplane
|
||||
|
||||
#Setup PushBullet
|
||||
from pushbullet import Pushbullet
|
||||
pb = Pushbullet("<pushbulletapikey>")
|
||||
elon_jet_channel = pb.get_channel('<channeltaghere>')
|
||||
|
||||
#Setup OpenSKy
|
||||
from opensky_api import OpenSkyApi
|
||||
opens_api = OpenSkyApi("<openskyusername>", "<openskypass>")
|
||||
|
||||
#Set Plane ICAO
|
||||
TRACK_PLANE = '<planeicaohere>'
|
||||
#Pre Set Variables
|
||||
geo_altitude = None
|
||||
geo_alt_ft = None
|
||||
last_geo_alt_ft = None
|
||||
last_below_5k_ft = None
|
||||
|
||||
last_below_desired_ft = None
|
||||
feeding = None
|
||||
last_feeding = None
|
||||
last_on_ground = None
|
||||
|
@ -39,9 +36,10 @@ takeoff_time = None
|
|||
#Begin Looping program
|
||||
while True:
|
||||
running_Count += 1
|
||||
start_time = time.time()
|
||||
print (Back.MAGENTA, "--------", running_Count, "-------------------------------------------------------------", Style.RESET_ALL)
|
||||
#Reset Variables
|
||||
below_5k_ft = None
|
||||
below_desired_ft = None
|
||||
geo_alt_ft = None
|
||||
longitude = None
|
||||
latitude = None
|
||||
|
@ -49,7 +47,7 @@ while True:
|
|||
geo_alt_m = None
|
||||
#Get API States for Plane
|
||||
planeData = None
|
||||
planeData = opens_api.get_states(time_secs=0, icao24=TRACK_PLANE.lower())
|
||||
planeData = pullplane(TRACK_PLANE)
|
||||
print (Fore.YELLOW)
|
||||
print ("OpenSky Debug", planeData)
|
||||
print(Style.RESET_ALL)
|
||||
|
@ -74,6 +72,7 @@ while True:
|
|||
print ("Latitude: ", latitude)
|
||||
print ("Longitude: ", longitude)
|
||||
print ("GEO Alitude Ft: ", geo_alt_ft)
|
||||
|
||||
#Lookup Location of coordinates
|
||||
if longitude != None and latitude != None:
|
||||
|
||||
|
@ -111,6 +110,7 @@ while True:
|
|||
elif invalid_Location is False:
|
||||
address = location.raw['address']
|
||||
country = address.get('country', '')
|
||||
country_code = address.get('country_code', '').upper()
|
||||
state = address.get('state', '')
|
||||
county = address.get('county', '')
|
||||
city = address.get('city', '')
|
||||
|
@ -123,7 +123,7 @@ while True:
|
|||
# print(Style.RESET_ALL)
|
||||
print (Fore.GREEN)
|
||||
print("Entire Address: ", location.address)
|
||||
print ()
|
||||
print ("Country Code: ", country_code)
|
||||
print ("Country: ", country)
|
||||
print ("State: ", state)
|
||||
print ("City: ", city)
|
||||
|
@ -132,45 +132,58 @@ while True:
|
|||
print ("County: ", county)
|
||||
print(Style.RESET_ALL)
|
||||
|
||||
#Check if below 10k ft
|
||||
#Check if below desire ft
|
||||
if geo_alt_ft is None:
|
||||
below_5k_ft = False
|
||||
elif geo_alt_ft < 5000:
|
||||
below_5k_ft = True
|
||||
below_desired_ft = False
|
||||
elif geo_alt_ft < 10000:
|
||||
below_desired_ft = True
|
||||
#Check if tookoff
|
||||
tookoff = bool(invalid_Location is False and below_5k_ft and on_ground is False and ((last_feeding is False and feeding) or (last_on_ground)))
|
||||
tookoff = bool(invalid_Location is False and below_desired_ft and on_ground is False and ((last_feeding is False and feeding) or (last_on_ground)))
|
||||
print ("Tookoff Just Now:", tookoff)
|
||||
|
||||
|
||||
#Check if Landed
|
||||
landed = bool(last_below_5k_ft and invalid_Location is False and ((last_feeding and feeding is False) or (on_ground and last_on_ground is False)))
|
||||
landed = bool(last_below_desired_ft and invalid_Location is False and ((last_feeding and feeding is False and last_on_ground is False) or (on_ground and last_on_ground is False)))
|
||||
print ("Landed Just Now:", landed)
|
||||
|
||||
|
||||
#Chose city town county or hamlet for location as not all are always avalible.
|
||||
if feeding and invalid_Location is False:
|
||||
aera_hierarchy = city or town or county or hamlet
|
||||
#Takeoff Notifcation and Landed
|
||||
if tookoff:
|
||||
tookoff_message = ("Just took off from" + " " + (city or county) + ", " + state + ", " + country)
|
||||
tookoff_message = ("Just took off from" + " " + aera_hierarchy + ", " + state + ", " + country_code)
|
||||
print (tookoff_message)
|
||||
push = elon_jet_channel.push_note("title", tookoff_message)
|
||||
takeoff_time = time.time()
|
||||
|
||||
|
||||
|
||||
if landed:
|
||||
landed_message = ("Landed just now at" + " " + (city or county) + ", " + state + ", " + country)
|
||||
landed_message = ("Landed just now in" + " " + aera_hierarchy + ", " + state + ", " + country_code)
|
||||
print (landed_message)
|
||||
push = elon_jet_channel.push_note("title", landed_message)
|
||||
|
||||
takeoff_time = None
|
||||
|
||||
|
||||
#Set Variables to compare to next check
|
||||
last_feeding = feeding
|
||||
last_geo_alt_ft = geo_alt_ft
|
||||
last_on_ground = on_ground
|
||||
last_below_5k_ft = below_5k_ft
|
||||
last_below_desired_ft = below_desired_ft
|
||||
|
||||
else:
|
||||
print ("Rechecking OpenSky")
|
||||
planeDataMSG = str(planeData)
|
||||
if takeoff_time != None:
|
||||
elapsed_time = time.time() - takeoff_time
|
||||
timesince = time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(elapsed_time))
|
||||
print(timesince)
|
||||
|
||||
|
||||
print (Back.MAGENTA, "--------", running_Count, "-------------------------------------------------------------", Style.RESET_ALL)
|
||||
|
||||
elapsed_calc_time = time.time() - start_time
|
||||
|
||||
print (Back.MAGENTA, "--------", running_Count, "------------------------Elapsed Time- ", elapsed_calc_time, "-------------------------------------", Style.RESET_ALL)
|
||||
print ("")
|
||||
time.sleep(15)
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
def pullplane(TRACK_PLANE):
|
||||
from opensky_api import OpenSkyApi
|
||||
opens_api = OpenSkyApi("<openskyusername>", "<openskypass>")
|
||||
planeData = opens_api.get_states(time_secs=0, icao24=TRACK_PLANE.lower())
|
||||
return planeData
|
Loading…
Reference in New Issue