Browse Source

Add Discord message conf, & simplify enables

single
Jxck-S 4 years ago
parent
commit
f287ccc496
  1. 19
      NotifyBot.py
  2. 19
      config.ini
  3. 2
      defDiscord.py

19
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

19
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

2
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')

Loading…
Cancel
Save