mirror of
https://github.com/caronc/apprise.git
synced 2025-01-20 21:08:38 +01:00
cli up and running
This commit is contained in:
parent
4e6e07e92d
commit
5ccc1cbeac
@ -200,7 +200,7 @@ class Apprise(object):
|
||||
status = len(self.servers) > 0
|
||||
|
||||
if notify_type and notify_type not in NOTIFY_TYPES:
|
||||
self.warning(
|
||||
logger.warning(
|
||||
'An invalid notification type (%s) was specified.' % (
|
||||
notify_type))
|
||||
|
||||
|
@ -61,7 +61,8 @@ class AppriseAsset(object):
|
||||
'apprise-{TYPE}-{XY}.png',
|
||||
))
|
||||
|
||||
def __init__(self, image_path_mask=None, image_url_mask=None, theme=None):
|
||||
def __init__(self, theme='default', image_path_mask=None,
|
||||
image_url_mask=None):
|
||||
"""
|
||||
Asset Initialization
|
||||
|
||||
@ -89,7 +90,7 @@ class AppriseAsset(object):
|
||||
|
||||
"""
|
||||
re_map = {
|
||||
'{THEME}': self.theme,
|
||||
'{THEME}': self.theme if self.theme else '',
|
||||
'{TYPE}': notify_type,
|
||||
'{XY}': image_size,
|
||||
}
|
||||
@ -108,7 +109,7 @@ class AppriseAsset(object):
|
||||
|
||||
"""
|
||||
re_map = {
|
||||
'{THEME}': self.theme,
|
||||
'{THEME}': self.theme if self.theme else '',
|
||||
'{TYPE}': notify_type,
|
||||
'{XY}': image_size,
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import logging
|
||||
import sys
|
||||
|
||||
from apprise import Apprise
|
||||
from apprise import AppriseAsset
|
||||
from apprise import NotifyType
|
||||
|
||||
# Logging
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -16,59 +18,60 @@ formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
# Defines our click context settings adding -h to the additional options that
|
||||
# can be specified to get the help menu to come up
|
||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
||||
|
||||
@click.command()
|
||||
|
||||
def print_help_msg(command):
|
||||
"""
|
||||
Prints help message when -h or --help is specified.
|
||||
|
||||
"""
|
||||
with click.Context(command) as ctx:
|
||||
click.echo(command.get_help(ctx))
|
||||
|
||||
|
||||
@click.command(context_settings=CONTEXT_SETTINGS)
|
||||
@click.option('--title', '-t', default=None, type=str,
|
||||
help='Specify the message title.')
|
||||
@click.option('--body', '-b', default=None, type=str,
|
||||
help='Specify the message body.')
|
||||
@click.option('--notification-type', '-t', default=NotifyType.INFO, type=str,
|
||||
metavar='TYPE', help='Specify the message type (default=info).')
|
||||
@click.option('--theme', '-T', default='default', type=str,
|
||||
help='Specify the default theme.')
|
||||
@click.option('--image-url', '-i', default=None, type=str,
|
||||
help='Specify the image URL.')
|
||||
@click.argument('urls', nargs=-1)
|
||||
def _main(title, body, urls, theme, image_url):
|
||||
@click.argument('urls', nargs=-1,
|
||||
metavar='SERVER_URL [SERVER_URL2 [SERVER_URL3]]',)
|
||||
def _main(title, body, urls, notification_type, theme):
|
||||
"""
|
||||
Notify all specified servers
|
||||
Send a notification to all of the specified servers identified by their
|
||||
URLs the content provided within the title, body and notification-type.
|
||||
|
||||
"""
|
||||
if not (title and body):
|
||||
logger.error('Neither a message body or title was specified.')
|
||||
return 1
|
||||
|
||||
if not urls:
|
||||
logger.error('You must specify at least one server URL')
|
||||
logger.error('You must specify at least one server URL.')
|
||||
print_help_msg(_main)
|
||||
return 1
|
||||
|
||||
# Prepare our asset
|
||||
asset = AppriseAsset(theme=theme)
|
||||
|
||||
# Create our object
|
||||
apprise = Apprise()
|
||||
apprise = Apprise(asset=asset)
|
||||
|
||||
# Load our inventory up
|
||||
for url in urls:
|
||||
apprise.add(url)
|
||||
|
||||
if body is None:
|
||||
# if no body was specified, then read from STDIN
|
||||
body = click.get_text_stream('stdin').read()
|
||||
|
||||
# now print it out
|
||||
apprise.notify(title=title, body=body)
|
||||
apprise.notify(title=title, body=body, notify_type=notification_type)
|
||||
|
||||
return 0
|
||||
# """\
|
||||
# Usage: apprise [options] [URL ...]
|
||||
#
|
||||
# Send notifications to a variety of different supported services.
|
||||
# See also https://github.com/caronc/apprise
|
||||
#
|
||||
# URL The notification service URL
|
||||
#
|
||||
# Options:
|
||||
#
|
||||
# -h, --help show this message
|
||||
# -t TITLE, --title TITLE Specify a notification title.
|
||||
# -b BODY, --body BODY Specify a notification body.
|
||||
# -i IMGURL, --image IMGURL Specify an image to send with the notification.
|
||||
# The image should be in the format of a URL
|
||||
# string such as file:///local/path/to/file.png or
|
||||
# a remote site like: http://my.host/my.image.png.
|
||||
# """
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user