code: def notify(args):
      
      from jcvi.utils.iter import flatten
  
      valid_notif_methods.extend(available_push_api.keys())
  
      fromaddr = get_email_address(whoami="notifier")
  
      p = OptionParser(notify.__doc__)
      p.add_option("--method", default="email", choices=valid_notif_methods,
                   help="Specify the mode of notification [default: %default]")
      p.add_option("--subject", default="JCVI: job monitor",
                   help="Specify the subject of the notification message")
      p.set_email()
  
      g1 = OptionGroup(p, "Optional `push` parameters")
      g1.add_option("--api", default="pushover", \
                    choices=list(flatten(available_push_api.values())),
                    help="Specify API used to send the push notification")
      g1.add_option("--priority", default=0, type="int",
                    help="Message priority (-1 <= p <= 2) [default: %default]")
      g1.add_option("--timestamp", default=None, type="int", \
                    dest="timestamp", \
                    help="Message timestamp in unix format [default: %default]")
      p.add_option_group(g1)
  
      opts, args = p.parse_args(args)
  
      if len(args) == 0:
          logging.error("Please provide a brief message to be sent")
          sys.exit(not p.print_help())
  
      subject = opts.subject
      message = " ".join(args).strip()
  
      if opts.method == "email":
          toaddr = opts.email.split(",")   # TO address should be in a list
          for addr in toaddr:
              if not is_valid_email(addr):
                  logging.debug("Email address `{0}` is not valid!".format(addr))
                  sys.exit()
          send_email(fromaddr, toaddr, subject, message)
      else:
          pushnotify(subject, message, api=opts.api, priority=opts.priority, \
                     timestamp=opts.timestamp)
docs: %prog notify "Message to be sent"
  
      Send a message via email/push notification.
  
      Email notify: Recipient email address is constructed by joining the login `username`
      and `dnsdomainname` of the server
  
      Push notify: Uses available API