mango-explorer/bin/send-notification

37 lines
1.5 KiB
Plaintext
Executable File

#!/usr/bin/env pyston3
import argparse
import logging
import os
import os.path
import sys
import traceback
sys.path.insert(0, os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')))
import mango # nopep8
# We explicitly want argument parsing to be outside the main try-except block because some arguments
# (like --help) will cause an exit, which our except: block traps.
parser = argparse.ArgumentParser(description="Sends SOL to a different address.")
parser.add_argument("--notification-target", type=mango.parse_subscription_target, required=True, action="append",
help="The notification target - a compound string that varies depending on the target")
parser.add_argument("--message", type=str, help="Message to send")
parser.add_argument("--log-level", default=logging.WARNING, type=lambda level: getattr(logging, level),
help="level of verbosity to log (possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL)")
args = parser.parse_args()
logging.getLogger().setLevel(args.log_level)
logging.warning(mango.WARNING_DISCLAIMER_TEXT)
try:
for notify in args.notification_target:
print("Sending to:", notify)
notify.send(args.message)
print("Notifications sent")
except Exception as exception:
logging.critical(f"send-sols stopped because of exception: {exception} - {traceback.format_exc()}")
except:
logging.critical(f"send-sols stopped because of uncatchable error: {traceback.format_exc()}")