Making fixes to get OOP version running

This commit is contained in:
Jxck-S 2020-09-14 10:56:06 -04:00
parent 490d33ae9d
commit cc97a5f328
5 changed files with 45 additions and 33 deletions

View File

@ -2,6 +2,7 @@ import requests
import configparser import configparser
import json import json
import time import time
from colorama import Fore, Back, Style
from planeClass import Plane from planeClass import Plane
main_config = configparser.ConfigParser() main_config = configparser.ConfigParser()
main_config.read('mainconf.ini') main_config.read('mainconf.ini')
@ -25,7 +26,11 @@ if main_config.get('DATA', 'SOURCE') == "ADSBX":
} }
elif main_config.get('DATA', 'SOURCE') == "OPENS": elif main_config.get('DATA', 'SOURCE') == "OPENS":
raise NotImplementedError raise NotImplementedError
running_Count = 0
while True: 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": if main_config.get('DATA', 'SOURCE') == "ADSBX":
try: try:
response = requests.get(url, headers = headers) response = requests.get(url, headers = headers)
@ -38,23 +43,26 @@ while True:
failed = True failed = True
except json.decoder.JSONDecodeError as error_message: except json.decoder.JSONDecodeError as error_message:
print("Error with JSON") print("Error with JSON")
print (json.dumps(data, indent = 2))
print(error_message) print(error_message)
failed = True failed = True
if failed == False: if failed == False:
print(data)
if data['ac'] != None: 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: if planeData['icao'] == key:
print(planeData['icao'])
print(planeData)
obj.run(planeData) obj.run(planeData)
else: has_data = True
obj.run(None) break
if has_data is False:
obj.run(None)
else: else:
for obj in planes.values(): for obj in planes.values():
obj.run(None) 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)

View File

@ -1,8 +1,9 @@
from discord_webhook import DiscordWebhook
import configparser def sendDis(message, map_file_name, conf_file):
config = configparser.ConfigParser() from discord_webhook import DiscordWebhook
config.read('config.ini') import configparser
def sendDis(message, map_file_name): config = configparser.ConfigParser()
config.read(conf_file)
webhook = DiscordWebhook(url=config.get('DISCORD', 'URL'), content=message, username=config.get('DISCORD', 'USERNAME')) webhook = DiscordWebhook(url=config.get('DISCORD', 'URL'), content=message, username=config.get('DISCORD', 'USERNAME'))
with open(map_file_name, "rb") as f: with open(map_file_name, "rb") as f:

View File

@ -1,9 +1,10 @@
# Authenticate to Twitter # Authenticate to Twitter
import configparser
config = configparser.ConfigParser() def tweepysetup(conf_file):
config.read('config.ini') import configparser
import tweepy config = configparser.ConfigParser()
def tweepysetup(): config.read(conf_file)
import tweepy
#DOCU #DOCU
#https://realpython.com/twitter-bot-python-tweepy/ #https://realpython.com/twitter-bot-python-tweepy/
auth = tweepy.OAuthHandler(config.get('TWITTER', 'CONSUMER_KEY'), config.get('TWITTER', 'CONSUMER_SECRET')) auth = tweepy.OAuthHandler(config.get('TWITTER', 'CONSUMER_KEY'), config.get('TWITTER', 'CONSUMER_SECRET'))

View File

@ -9,6 +9,12 @@ CONSUMER_SECRET = cshere
ACCESS_TOKEN = athere ACCESS_TOKEN = athere
ACCESS_TOKEN_SECRET = atshere 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] [PUSHBULLET]
ENABLE = FALSE ENABLE = FALSE
TITLE = Title Of Pushbullet message TITLE = Title Of Pushbullet message

View File

@ -12,7 +12,6 @@ class Plane:
self.invalid_Location = None self.invalid_Location = None
self.longitude = None self.longitude = None
self.latitude = None self.latitude = None
self.running_Count = 0
self.callsign = None self.callsign = None
self.takeoff_time = None self.takeoff_time = None
self.reg = None self.reg = None
@ -49,18 +48,16 @@ class Plane:
#Setup Tweepy #Setup Tweepy
if self.config.getboolean('TWITTER', 'ENABLE'): if self.config.getboolean('TWITTER', 'ENABLE'):
from defTweet import tweepysetup from defTweet import tweepysetup
self.tweet_api = tweepysetup() self.tweet_api = tweepysetup(self.conf_file)
#Setup PushBullet #Setup PushBullet
if self.config.getboolean('PUSHBULLET', 'ENABLE'): if self.config.getboolean('PUSHBULLET', 'ENABLE'):
from pushbullet import Pushbullet from pushbullet import Pushbullet
self.pb = Pushbullet(self.config['PUSHBULLET']['API_KEY']) 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 #Pre Set Non Reseting Variables
self.running_Count +=1 print (Back.MAGENTA, "---------", self.conf_file, "---------------------------- ICAO:", self.icao, "--------------------------", Style.RESET_ALL)
self.start_time = time.time()
print (Back.MAGENTA, "--------", self.running_Count, "----------------------------- ICAO:", self.icao, "--------------------------", Style.RESET_ALL)
#Reset Variables #Reset Variables
self.below_desired_ft = None self.below_desired_ft = None
self.geo_alt_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 self.aera_hierarchy = self.city or self.town or self.county or self.hamlet
#Takeoff Notifcation and Landed #Takeoff Notifcation and Landed
if self.tookoff: if self.tookoff:
tookoff_message = ("Just took off from" + " " + self.aera_hierarchy + ", " + self.state + ", " + self.country_code) self.tookoff_message = ("Just took off from" + " " + self.aera_hierarchy + ", " + self.state + ", " + self.country_code)
print (tookoff_message) print (self.tookoff_message)
#Google Map or tar1090 screenshot #Google Map or tar1090 screenshot
if self.config.getboolean('GOOGLE', 'STATICMAP_ENABLE'): if self.config.getboolean('GOOGLE', 'STATICMAP_ENABLE'):
getMap(self.aera_hierarchy + ", " + self.state + ", " + self.country_code) getMap(self.aera_hierarchy + ", " + self.state + ", " + self.country_code)
@ -204,7 +201,7 @@ class Plane:
#Discord #Discord
if self.config.getboolean('DISCORD', 'ENABLE'): if self.config.getboolean('DISCORD', 'ENABLE'):
self.dis_message = self.config.get('DISCORD', 'TITLE') + " " + self.tookoff_message 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 #PushBullet
if self.config.getboolean('PUSHBULLET', 'ENABLE'): if self.config.getboolean('PUSHBULLET', 'ENABLE'):
with open(self.map_file_name, "rb") as pic: 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 = 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_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) 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 #Google Map or tar1090 screenshot
if self.config.getboolean('GOOGLE', 'STATICMAP_ENABLE'): if self.config.getboolean('GOOGLE', 'STATICMAP_ENABLE'):
getMap(self.aera_hierarchy + ", " + self.state + ", " + self.country_code) getMap(self.aera_hierarchy + ", " + self.state + ", " + self.country_code)
@ -233,7 +230,7 @@ class Plane:
#Discord #Discord
if self.config.getboolean('DISCORD', 'ENABLE'): if self.config.getboolean('DISCORD', 'ENABLE'):
self.dis_message = self.config.get('DISCORD', 'TITLE') + " " + self.landed_message 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 #PushBullet
if self.config.getboolean('PUSHBULLET', 'ENABLE'): if self.config.getboolean('PUSHBULLET', 'ENABLE'):
with open(self.map_file_name, "rb") as pic: 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") print ("Failed to Parse Will Recheck this Plane After new data")
if self.takeoff_time != None: 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)) 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) 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)