Add Discord message conf, & simplify enables
This commit is contained in:
parent
ae6517c654
commit
f287ccc496
19
NotifyBot.py
19
NotifyBot.py
|
@ -30,16 +30,11 @@ if config.getboolean('DISCORD', 'ENABLE'):
|
||||||
if config.getboolean('TWITTER', 'ENABLE'):
|
if config.getboolean('TWITTER', 'ENABLE'):
|
||||||
from defTweet import tweepysetup
|
from defTweet import tweepysetup
|
||||||
tweet_api = tweepysetup()
|
tweet_api = tweepysetup()
|
||||||
else:
|
|
||||||
tweet_api = None
|
|
||||||
#Setup PushBullet
|
#Setup PushBullet
|
||||||
if config.getboolean('PUSHBULLET', 'ENABLE'):
|
if config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||||
from pushbullet import Pushbullet
|
from pushbullet import Pushbullet
|
||||||
pb = Pushbullet(config['PUSHBULLET']['API_KEY'])
|
pb = Pushbullet(config['PUSHBULLET']['API_KEY'])
|
||||||
pb_channel = pb.get_channel(config.get('PUSHBULLET', 'CHANNEL_TAG'))
|
pb_channel = pb.get_channel(config.get('PUSHBULLET', 'CHANNEL_TAG'))
|
||||||
else:
|
|
||||||
pb_channel = None
|
|
||||||
pb = None
|
|
||||||
|
|
||||||
#Set Plane ICAO
|
#Set Plane ICAO
|
||||||
icao = config.get('DATA', 'ICAO').upper()
|
icao = config.get('DATA', 'ICAO').upper()
|
||||||
|
@ -54,7 +49,6 @@ on_ground = None
|
||||||
invalid_Location = None
|
invalid_Location = None
|
||||||
longitude = None
|
longitude = None
|
||||||
latitude = None
|
latitude = None
|
||||||
geo_alt_m = None
|
|
||||||
running_Count = 0
|
running_Count = 0
|
||||||
callsign = None
|
callsign = None
|
||||||
takeoff_time = None
|
takeoff_time = None
|
||||||
|
@ -70,7 +64,6 @@ while True:
|
||||||
longitude = None
|
longitude = None
|
||||||
latitude = None
|
latitude = None
|
||||||
on_ground = None
|
on_ground = None
|
||||||
geo_alt_m = None
|
|
||||||
#Get API States for Plane
|
#Get API States for Plane
|
||||||
plane_Dict = None
|
plane_Dict = None
|
||||||
if config.get('DATA', 'SOURCE') == "OPENS":
|
if config.get('DATA', 'SOURCE') == "OPENS":
|
||||||
|
@ -195,16 +188,16 @@ while True:
|
||||||
getSS(icao)
|
getSS(icao)
|
||||||
#Discord
|
#Discord
|
||||||
if config.getboolean('DISCORD', 'ENABLE'):
|
if config.getboolean('DISCORD', 'ENABLE'):
|
||||||
dis_message = icao + " " + tookoff_message
|
dis_message = config.get('DISCORD', 'TITLE') + " " + tookoff_message
|
||||||
sendDis(dis_message)
|
sendDis(dis_message)
|
||||||
#PushBullet
|
#PushBullet
|
||||||
if pb != None:
|
if config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||||
with open("map.png", "rb") as pic:
|
with open("map.png", "rb") as pic:
|
||||||
map_data = pb.upload_file(pic, "Tookoff IMG")
|
map_data = pb.upload_file(pic, "Tookoff IMG")
|
||||||
push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), tookoff_message)
|
push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), tookoff_message)
|
||||||
push = pb_channel.push_file(**map_data)
|
push = pb_channel.push_file(**map_data)
|
||||||
#Twitter
|
#Twitter
|
||||||
if tweet_api != None:
|
if config.getboolean('TWITTER', 'ENABLE'):
|
||||||
tweet_api.update_with_media("map.png", status = tookoff_message)
|
tweet_api.update_with_media("map.png", status = tookoff_message)
|
||||||
takeoff_time = time.time()
|
takeoff_time = time.time()
|
||||||
os.remove("map.png")
|
os.remove("map.png")
|
||||||
|
@ -224,16 +217,16 @@ while True:
|
||||||
getSS(icao)
|
getSS(icao)
|
||||||
#Discord
|
#Discord
|
||||||
if config.getboolean('DISCORD', 'ENABLE'):
|
if config.getboolean('DISCORD', 'ENABLE'):
|
||||||
dis_message = icao + " " + landed_message
|
dis_message = config.get('DISCORD', 'TITLE') + " " + landed_message
|
||||||
sendDis(dis_message)
|
sendDis(dis_message)
|
||||||
#PushBullet
|
#PushBullet
|
||||||
if pb != None:
|
if config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||||
with open("map.png", "rb") as pic:
|
with open("map.png", "rb") as pic:
|
||||||
map_data = pb.upload_file(pic, "Landed IMG")
|
map_data = pb.upload_file(pic, "Landed IMG")
|
||||||
push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), landed_message)
|
push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), landed_message)
|
||||||
push = pb_channel.push_file(**map_data)
|
push = pb_channel.push_file(**map_data)
|
||||||
#Twitter
|
#Twitter
|
||||||
if tweet_api != None:
|
if config.getboolean('TWITTER', 'ENABLE'):
|
||||||
tweet_api.update_with_media("map.png", status = landed_message)
|
tweet_api.update_with_media("map.png", status = landed_message)
|
||||||
takeoff_time = None
|
takeoff_time = None
|
||||||
landed_time = None
|
landed_time = None
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#V2
|
|
||||||
[DATA]
|
[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
|
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
|
#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
|
#By default configured with OpenSky which anyone can use without a login
|
||||||
|
@ -13,6 +13,7 @@ SOURCE = OPENS
|
||||||
API_KEY = apikey
|
API_KEY = apikey
|
||||||
|
|
||||||
#OpenSky https://opensky-network.org/apidoc/index.html
|
#OpenSky https://opensky-network.org/apidoc/index.html
|
||||||
|
#When using without your own login user and pass should be None
|
||||||
[OPENSKY]
|
[OPENSKY]
|
||||||
USERNAME = None
|
USERNAME = None
|
||||||
PASSWORD = None
|
PASSWORD = None
|
||||||
|
@ -39,4 +40,6 @@ CHANNEL_TAG = channeltag
|
||||||
[DISCORD]
|
[DISCORD]
|
||||||
ENABLE = TRUE
|
ENABLE = TRUE
|
||||||
#WEBHOOK URL https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
#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
|
||||||
|
|
|
@ -3,7 +3,7 @@ import configparser
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('config.ini')
|
config.read('config.ini')
|
||||||
def sendDis(message):
|
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:
|
with open("map.png", "rb") as f:
|
||||||
webhook.add_file(file=f.read(), filename='map.png')
|
webhook.add_file(file=f.read(), filename='map.png')
|
||||||
|
|
Loading…
Reference in New Issue