Esempio n. 1
0
    def notify(self, servers, body, title, notify_type=NotifyType.INFO,
               body_format=NotifyFormat.MARKDOWN):
        """
        processes list of servers specified
        """

        # Apprise Asset Object
        asset = AppriseAsset(theme=self.default_theme)
        asset.app_id = 'NZB-Notify'
        asset.app_desc = 'NZB Notification'
        asset.app_url = 'https://github.com/caronc/nzb-notify'

        # Source Theme from GitHub Page
        asset.image_url_mask = 'https://raw.githubusercontent.com' \
                               '/caronc/nzb-notify/master/Notify' \
                               '/apprise-theme/{THEME}/apprise-{TYPE}-{XY}.png'

        asset.image_path_mask = join(
            dirname(__file__),
            'Notify', 'apprise-theme', '{THEME}',
            'apprise-{TYPE}-{XY}.png')

        # Include Image Flag
        _url = self.parse_url(self.get('IncludeImage'))

        # Define some globals to use in this function
        image_path = None
        image_url = None

        if _url:
            # Toggle our include image flag right away to True
            include_image = True

            # Get some more details
            if not re.match('^(https?|file)$', _url['schema'] ,re.IGNORECASE):
                self.logger.error(
                    'An invalid image url protocol (%s://) was specified.' % \
                     _url['schema'],
                )
                return False

            if _url['schema'] == 'file':
                if not isile(_url['fullpath']):
                    self.logger.error(
                        'The specified file %s was not found.' % \
                        _url['fullpath'],
                    )
                    return False
                image_path = _url['fullpath']

            else:
                # We're dealing with a web request
                image_url = _url['url']

        else:
            # Dealing with the old way of doing things; just toggling a true/false
            # flag
            include_image = self.parse_bool(self.get('IncludeImage'), False)

        if isinstance(servers, basestring):
            # servers can be a list of URLs, or it can be
            # a string which will be parsed into this list
            # we wanted.
            servers = self.parse_list(self.get('Servers', ''))

        # Create our apprise object
        a = Apprise(asset=asset)

        for server in servers:

            # Add our URL
            if not a.add(server):
                # Validation Failure
                self.logger.error(
                    'Could not initialize %s instance.' % server,
                )
                continue

        # Notify our servers
        a.notify(body=body, title=title, notify_type=notify_type,
                 body_format=body_format)

        # Always return true
        return True
Esempio n. 2
0
import random
import string
from string import Template

# 3rd party
import gevent
from apprise import Apprise
from apprise import AppriseAsset

# betanin
import betanin.config.betanin as conf_betanin
from betanin.status import Status

_apprise_asset = AppriseAsset()
_apprise_asset.app_id = "betanin"
_apprise_asset.app_desc = "betanin"
APPRISE = Apprise(asset=_apprise_asset)
STATUS_LONG = {
    Status.COMPLETED: "has completed",
    Status.FAILED: "has failed",
    Status.NEEDS_INPUT: "needs input",
}


def _random_string(size=6, chars=string.ascii_lowercase + string.digits):
    return "".join(random.choice(chars) for x in range(size))


def _make_templates(config):
    return {
        "title": Template(config["notifications"]["strings"]["title"]),
Esempio n. 3
0
    def notify(self, servers, body, title, notify_type=NotifyType.INFO,
               body_format=NotifyFormat.MARKDOWN):
        """
        processes list of servers specified
        """

        # Decode our data
        body = decode(body)
        title = decode(title)

        # Apprise Asset Object
        asset = AppriseAsset(theme=self.default_theme)
        asset.app_id = 'NZB-Notify'
        asset.app_desc = 'NZB Notification'
        asset.app_url = 'https://github.com/caronc/nzb-notify'

        # Source Theme from GitHub Page
        asset.image_url_mask = 'https://raw.githubusercontent.com' \
                               '/caronc/nzb-notify/master/Notify' \
                               '/apprise-theme/{THEME}/apprise-{TYPE}-{XY}.png'

        asset.image_path_mask = join(
            dirname(__file__),
            'Notify', 'apprise-theme', '{THEME}',
            'apprise-{TYPE}-{XY}.png')

        # Include Image Flag
        _url = self.parse_url(self.get('IncludeImage'))

        # Define some globals to use in this function
        image_path = None
        image_url = None

        if _url:
            # Toggle our include image flag right away to True
            include_image = True

            # Get some more details
            if not re.match('^(https?|file)$', _url['schema'], re.IGNORECASE):
                self.logger.error(
                    'An invalid image url protocol (%s://) was specified.' %
                    _url['schema'],
                )
                return False

            if _url['schema'] == 'file':
                if not isfile(_url['fullpath']):
                    self.logger.error(
                        'The specified file %s was not found.' %
                        _url['fullpath'],
                    )
                    return False
                image_path = _url['fullpath']

            else:
                # We're dealing with a web request
                image_url = _url['url']

        else:
            # Dealing with the old way of doing things; just toggling a
            # true/false flag
            include_image = self.parse_bool(self.get('IncludeImage'), False)

        if isinstance(servers, basestring):
            # servers can be a list of URLs, or it can be
            # a string which will be parsed into this list
            # we wanted.
            servers = self.parse_list(self.get('Servers', ''))

        # Create our apprise object
        a = Apprise(asset=asset)

        for server in servers:

            # Add our URL
            if not a.add(server):
                # Validation Failure
                self.logger.error(
                    'Could not initialize %s instance.' % server,
                )
                continue

        # Notify our servers
        a.notify(body=body, title=title, notify_type=notify_type,
                 body_format=body_format)

        # Always return true
        return True