From f287ccc496deb91c78087e38a9f98a2ac80a8227 Mon Sep 17 00:00:00 2001 From: Jxck-S Date: Mon, 17 Aug 2020 23:32:11 -0400 Subject: [PATCH] Add Discord message conf, & simplify enables --- NotifyBot.py | 19 ++++++------------- config.ini | 19 +++++++++++-------- defDiscord.py | 2 +- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/NotifyBot.py b/NotifyBot.py index 35b1927..4501e6e 100644 --- a/NotifyBot.py +++ b/NotifyBot.py @@ -30,16 +30,11 @@ if config.getboolean('DISCORD', 'ENABLE'): if config.getboolean('TWITTER', 'ENABLE'): from defTweet import tweepysetup tweet_api = tweepysetup() -else: - tweet_api = None #Setup PushBullet if config.getboolean('PUSHBULLET', 'ENABLE'): from pushbullet import Pushbullet pb = Pushbullet(config['PUSHBULLET']['API_KEY']) pb_channel = pb.get_channel(config.get('PUSHBULLET', 'CHANNEL_TAG')) -else: - pb_channel = None - pb = None #Set Plane ICAO icao = config.get('DATA', 'ICAO').upper() @@ -54,7 +49,6 @@ on_ground = None invalid_Location = None longitude = None latitude = None -geo_alt_m = None running_Count = 0 callsign = None takeoff_time = None @@ -70,7 +64,6 @@ while True: longitude = None latitude = None on_ground = None - geo_alt_m = None #Get API States for Plane plane_Dict = None if config.get('DATA', 'SOURCE') == "OPENS": @@ -195,16 +188,16 @@ while True: getSS(icao) #Discord if config.getboolean('DISCORD', 'ENABLE'): - dis_message = icao + " " + tookoff_message + dis_message = config.get('DISCORD', 'TITLE') + " " + tookoff_message sendDis(dis_message) #PushBullet - if pb != None: + if config.getboolean('PUSHBULLET', 'ENABLE'): with open("map.png", "rb") as pic: map_data = pb.upload_file(pic, "Tookoff IMG") push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), tookoff_message) push = pb_channel.push_file(**map_data) #Twitter - if tweet_api != None: + if config.getboolean('TWITTER', 'ENABLE'): tweet_api.update_with_media("map.png", status = tookoff_message) takeoff_time = time.time() os.remove("map.png") @@ -224,16 +217,16 @@ while True: getSS(icao) #Discord if config.getboolean('DISCORD', 'ENABLE'): - dis_message = icao + " " + landed_message + dis_message = config.get('DISCORD', 'TITLE') + " " + landed_message sendDis(dis_message) #PushBullet - if pb != None: + if config.getboolean('PUSHBULLET', 'ENABLE'): with open("map.png", "rb") as pic: map_data = pb.upload_file(pic, "Landed IMG") push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), landed_message) push = pb_channel.push_file(**map_data) #Twitter - if tweet_api != None: + if config.getboolean('TWITTER', 'ENABLE'): tweet_api.update_with_media("map.png", status = landed_message) takeoff_time = None landed_time = None diff --git a/config.ini b/config.ini index c06f2e7..3e3b705 100644 --- a/config.ini +++ b/config.ini @@ -1,25 +1,26 @@ -#V2 [DATA] -#Plane to track, based of ICAO or ICAO24 which is the unique transponder address of a plane. +#Plane to track, based of ICAO or ICAO24 which is the unique transponder address of a plane. ICAO = planeicaohere -#Source to pull data from + +#Source to pull data from #SHOULD BE ADSBX which is ADS-B Exchange or OPENS which is OpenSky #By default configured with OpenSky which anyone can use without a login #ADS-B Exchange has better data but is not avalible unless you feed their network or pay. SOURCE = OPENS -#ADS-B Exchange https://www.adsbexchange.com/data/ +#ADS-B Exchange https://www.adsbexchange.com/data/ [ADSBX] API_KEY = apikey #OpenSky https://opensky-network.org/apidoc/index.html +#When using without your own login user and pass should be None [OPENSKY] USERNAME = None PASSWORD = None [GOOGLE] #API KEYS -#If static map disabled will load up tar1090 ads-b exchange and take screenshot instead. +#If static map disabled will load up tar1090 ads-b exchange and take screenshot instead. STATICMAP_ENABLE = FALSE STATICMAPKEY = googleapikey @@ -33,10 +34,12 @@ ACCESS_TOKEN_SECRET = atshere [PUSHBULLET] ENABLE = FALSE TITLE = Title Of Pushbullet message -API_KEY = apikey -CHANNEL_TAG = channeltag +API_KEY = apikey +CHANNEL_TAG = channeltag [DISCORD] ENABLE = TRUE #WEBHOOK URL https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks -URL = webhookurlhere +URL = webhookhere +Title = title in front of message +USERNAME = username of user in channel can be anything diff --git a/defDiscord.py b/defDiscord.py index df99369..3cfaa70 100644 --- a/defDiscord.py +++ b/defDiscord.py @@ -3,7 +3,7 @@ import configparser config = configparser.ConfigParser() config.read('config.ini') def sendDis(message): - webhook = DiscordWebhook(url=config.get('DISCORD', 'URL'), content=message, username="plane-notify") + webhook = DiscordWebhook(url=config.get('DISCORD', 'URL'), content=message, username=config.get('DISCORD', 'USERNAME')) with open("map.png", "rb") as f: webhook.add_file(file=f.read(), filename='map.png')