From fde586589f756becad2ad245d27a0bc934fad200 Mon Sep 17 00:00:00 2001 From: Jxck-S Date: Tue, 2 Feb 2021 20:52:33 -0500 Subject: [PATCH] Added Discord enable/disable option for main --- NotifyBotMulti.py | 22 +++++++++++++--------- configs/mainconf.ini | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/NotifyBotMulti.py b/NotifyBotMulti.py index 84606eb..86a8ab1 100644 --- a/NotifyBotMulti.py +++ b/NotifyBotMulti.py @@ -30,9 +30,10 @@ for file in required_files: main_config = configparser.ConfigParser() main_config.read('./configs/mainconf.ini') source = main_config.get('DATA', 'SOURCE') -from discord_webhook import DiscordWebhook -webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Started"))) -webhook.execute() +if main_config.getboolean('DISCORD', 'ENABLE'): + from discord_webhook import DiscordWebhook + webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Started"))) + webhook.execute() try: print("Source is set to", source) import sys @@ -118,8 +119,9 @@ try: elif source == "ADSBX": source = "OPENS" failed_count = 0 - webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Failed over to " + source))) - webhook.execute() + if main_config.getboolean('DISCORD', 'ENABLE'): + webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Failed over to " + source))) + webhook.execute() elapsed_calc_time = time.time() - start_time datetime_tz = datetime.now(tz) footer = "-------- " + str(running_Count) + " -------- " + str(datetime_tz.strftime("%I:%M:%S %p")) + " ------------------------Elapsed Time- " + str(round(elapsed_calc_time, 3)) + " -------------------------------------" @@ -138,10 +140,12 @@ try: print() except KeyboardInterrupt as e: print(e) - webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Manual Exit: " + str(e) ))) - webhook.execute() + if main_config.getboolean('DISCORD', 'ENABLE'): + webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Manual Exit: " + str(e) ))) + webhook.execute() except BaseException as e: print(e) print(traceback.format_exc()) - webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Error Exiting: " + str(e) ))) - webhook.execute() \ No newline at end of file + if main_config.getboolean('DISCORD', 'ENABLE'): + webhook = DiscordWebhook(url= main_config.get('DISCORD', 'URL'), content=(str("Error Exiting: " + str(e) ))) + webhook.execute() \ No newline at end of file diff --git a/configs/mainconf.ini b/configs/mainconf.ini index 16bbf8a..fbc18bb 100644 --- a/configs/mainconf.ini +++ b/configs/mainconf.ini @@ -29,5 +29,6 @@ API_KEY = googleapikey #Used for failover messages [DISCORD] +ENABLE = FALSE URL = webhookurl