Making fixes to get OOP version running
This commit is contained in:
parent
aeede2633d
commit
83b1e71c54
|
@ -2,6 +2,7 @@ import requests
|
|||
import configparser
|
||||
import json
|
||||
import time
|
||||
from colorama import Fore, Back, Style
|
||||
from planeClass import Plane
|
||||
main_config = configparser.ConfigParser()
|
||||
main_config.read('mainconf.ini')
|
||||
|
@ -25,7 +26,11 @@ if main_config.get('DATA', 'SOURCE') == "ADSBX":
|
|||
}
|
||||
elif main_config.get('DATA', 'SOURCE') == "OPENS":
|
||||
raise NotImplementedError
|
||||
running_Count = 0
|
||||
while True:
|
||||
running_Count +=1
|
||||
start_time = time.time()
|
||||
print (Back.GREEN, Fore.BLACK, "--------", running_Count, "-------------------------------------------------------", Style.RESET_ALL)
|
||||
if main_config.get('DATA', 'SOURCE') == "ADSBX":
|
||||
try:
|
||||
response = requests.get(url, headers = headers)
|
||||
|
@ -38,23 +43,26 @@ while True:
|
|||
failed = True
|
||||
except json.decoder.JSONDecodeError as error_message:
|
||||
print("Error with JSON")
|
||||
print (json.dumps(data, indent = 2))
|
||||
print(error_message)
|
||||
failed = True
|
||||
|
||||
if failed == False:
|
||||
print(data)
|
||||
if data['ac'] != None:
|
||||
for planeData in data['ac']:
|
||||
for key, obj in planes.items():
|
||||
for key, obj in planes.items():
|
||||
has_data = False
|
||||
for planeData in data['ac']:
|
||||
if planeData['icao'] == key:
|
||||
print(planeData['icao'])
|
||||
print(planeData)
|
||||
obj.run(planeData)
|
||||
else:
|
||||
obj.run(None)
|
||||
has_data = True
|
||||
break
|
||||
if has_data is False:
|
||||
obj.run(None)
|
||||
else:
|
||||
for obj in planes.values():
|
||||
obj.run(None)
|
||||
elapsed_calc_time = time.time() - start_time
|
||||
print (Back.GREEN, Fore.BLACK, "--------", running_Count, "------------------------Elapsed Time-", elapsed_calc_time, " -------------------------------------", Style.RESET_ALL)
|
||||
print(Back.RED, "Sleep 30", Style.RESET_ALL)
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
time.sleep(15)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from discord_webhook import DiscordWebhook
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
def sendDis(message, map_file_name):
|
||||
|
||||
def sendDis(message, map_file_name, conf_file):
|
||||
from discord_webhook import DiscordWebhook
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read(conf_file)
|
||||
webhook = DiscordWebhook(url=config.get('DISCORD', 'URL'), content=message, username=config.get('DISCORD', 'USERNAME'))
|
||||
|
||||
with open(map_file_name, "rb") as f:
|
||||
|
|
11
defTweet.py
11
defTweet.py
|
@ -1,9 +1,10 @@
|
|||
# Authenticate to Twitter
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
import tweepy
|
||||
def tweepysetup():
|
||||
|
||||
def tweepysetup(conf_file):
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read(conf_file)
|
||||
import tweepy
|
||||
#DOCU
|
||||
#https://realpython.com/twitter-bot-python-tweepy/
|
||||
auth = tweepy.OAuthHandler(config.get('TWITTER', 'CONSUMER_KEY'), config.get('TWITTER', 'CONSUMER_SECRET'))
|
||||
|
|
|
@ -9,6 +9,12 @@ CONSUMER_SECRET = cshere
|
|||
ACCESS_TOKEN = athere
|
||||
ACCESS_TOKEN_SECRET = atshere
|
||||
|
||||
[GOOGLE]
|
||||
#API KEYS
|
||||
#If static map disabled will load up tar1090 ads-b exchange and take screenshot instead.
|
||||
STATICMAP_ENABLE = FALSE
|
||||
STATICMAPKEY = googleapikey
|
||||
|
||||
[PUSHBULLET]
|
||||
ENABLE = FALSE
|
||||
TITLE = Title Of Pushbullet message
|
||||
|
|
|
@ -12,7 +12,6 @@ class Plane:
|
|||
self.invalid_Location = None
|
||||
self.longitude = None
|
||||
self.latitude = None
|
||||
self.running_Count = 0
|
||||
self.callsign = None
|
||||
self.takeoff_time = None
|
||||
self.reg = None
|
||||
|
@ -49,18 +48,16 @@ class Plane:
|
|||
#Setup Tweepy
|
||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||
from defTweet import tweepysetup
|
||||
self.tweet_api = tweepysetup()
|
||||
self.tweet_api = tweepysetup(self.conf_file)
|
||||
#Setup PushBullet
|
||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||
from pushbullet import Pushbullet
|
||||
self.pb = Pushbullet(self.config['PUSHBULLET']['API_KEY'])
|
||||
self.pb_channel = pb.get_channel(self.config.get('PUSHBULLET', 'CHANNEL_TAG'))
|
||||
self.pb_channel = self.pb.get_channel(self.config.get('PUSHBULLET', 'CHANNEL_TAG'))
|
||||
|
||||
#Pre Set Non Reseting Variables
|
||||
|
||||
self.running_Count +=1
|
||||
self.start_time = time.time()
|
||||
print (Back.MAGENTA, "--------", self.running_Count, "----------------------------- ICAO:", self.icao, "--------------------------", Style.RESET_ALL)
|
||||
print (Back.MAGENTA, "---------", self.conf_file, "---------------------------- ICAO:", self.icao, "--------------------------", Style.RESET_ALL)
|
||||
#Reset Variables
|
||||
self.below_desired_ft = None
|
||||
self.geo_alt_ft = None
|
||||
|
@ -194,8 +191,8 @@ class Plane:
|
|||
self.aera_hierarchy = self.city or self.town or self.county or self.hamlet
|
||||
#Takeoff Notifcation and Landed
|
||||
if self.tookoff:
|
||||
tookoff_message = ("Just took off from" + " " + self.aera_hierarchy + ", " + self.state + ", " + self.country_code)
|
||||
print (tookoff_message)
|
||||
self.tookoff_message = ("Just took off from" + " " + self.aera_hierarchy + ", " + self.state + ", " + self.country_code)
|
||||
print (self.tookoff_message)
|
||||
#Google Map or tar1090 screenshot
|
||||
if self.config.getboolean('GOOGLE', 'STATICMAP_ENABLE'):
|
||||
getMap(self.aera_hierarchy + ", " + self.state + ", " + self.country_code)
|
||||
|
@ -204,7 +201,7 @@ class Plane:
|
|||
#Discord
|
||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
self.dis_message = self.config.get('DISCORD', 'TITLE') + " " + self.tookoff_message
|
||||
sendDis(dis_message, self.map_file_name)
|
||||
sendDis(self.dis_message, self.map_file_name, self.conf_file)
|
||||
#PushBullet
|
||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||
with open(self.map_file_name, "rb") as pic:
|
||||
|
@ -224,7 +221,7 @@ class Plane:
|
|||
self.landed_time = time.time() - self.takeoff_time
|
||||
self.landed_time_msg = time.strftime("Apx. flt. time %H Hours : %M Mins ", self.time.gmtime(landed_time))
|
||||
self.landed_message = ("Landed just now in" + " " + self.aera_hierarchy + ", " + self.state + ", " + self.country_code + ". " + self.landed_time_msg)
|
||||
print (landed_message)
|
||||
print (self.landed_message)
|
||||
#Google Map or tar1090 screenshot
|
||||
if self.config.getboolean('GOOGLE', 'STATICMAP_ENABLE'):
|
||||
getMap(self.aera_hierarchy + ", " + self.state + ", " + self.country_code)
|
||||
|
@ -233,7 +230,7 @@ class Plane:
|
|||
#Discord
|
||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
self.dis_message = self.config.get('DISCORD', 'TITLE') + " " + self.landed_message
|
||||
sendDis(self.dis_message, self.map_file_name)
|
||||
sendDis(self.dis_message, self.map_file_name, self.conf_file)
|
||||
#PushBullet
|
||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||
with open(self.map_file_name, "rb") as pic:
|
||||
|
@ -258,12 +255,11 @@ class Plane:
|
|||
print ("Failed to Parse Will Recheck this Plane After new data")
|
||||
|
||||
if self.takeoff_time != None:
|
||||
self.elapsed_time = self.time.time() - self.takeoff_time
|
||||
self.elapsed_time = time.time() - self.takeoff_time
|
||||
self.time_since_tk = self.time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(self.elapsed_time))
|
||||
print(self.time_since_tk)
|
||||
|
||||
|
||||
|
||||
self.elapsed_calc_time = time.time() - self.start_time
|
||||
|
||||
print (Back.MAGENTA, "--------", self.running_Count, "------------------------Elapsed Time- ", self.elapsed_calc_time, "-------------------------------------", Style.RESET_ALL)
|
||||
print (Back.MAGENTA, "---------------------------------------------------------------------------", Style.RESET_ALL)
|
||||
|
|
Loading…
Reference in New Issue