コード例 #1
0
ファイル: scheduler.py プロジェクト: jacob2826/WebMonitor
def send_message(content, header, mail, wechat, pushover):
    from app.main.notification.notification_handler import new_handler

    total = 0
    fail = 0

    exception_content = ''
    try:
        if mail == 'yes':
            total += 1
            handler = new_handler('mail')
            mail_info = Notification.query.filter_by(type='mail').first()
            mail_address = mail_info.number
            content = markdown.markdown(content,
                                        output_format='html5',
                                        extensions=['extra'])
            handler.send(mail_address, header, content)
    except Exception as e:
        fail += 1
        exception_content += 'Mail Exception: {};'.format(repr(e))

    try:
        if wechat == 'yes':
            total += 1
            handler = new_handler('wechat')
            wechat_info = Notification.query.filter_by(type='wechat').first()
            key = wechat_info.number
            handler.send(key, header, content)
    except Exception as e:
        fail += 1
        exception_content += 'Wechat Exception: {};'.format(repr(e))

    try:
        if pushover == 'yes':
            total += 1
            handler = new_handler('pushover')
            pushover_info = Notification.query.filter_by(
                type='pushover').first()
            key = pushover_info.number
            handler.send(key, header, content)
    except Exception as e:
        fail += 1
        exception_content += 'Pushover Exception: {};'.format(repr(e))

    if fail > 0:
        if fail < total:
            raise PartNotificationError(exception_content)
        else:
            raise Exception(exception_content)
コード例 #2
0
def send_message(content, header, mail, wechat):
    from app.main.notification.notification_handler import new_handler

    mail_exception = None
    try:
        if mail == 'yes':
            handler = new_handler('mail')
            mail_info = Notification.query.filter_by(type='mail').first()
            mail_address = mail_info.number
            content = markdown.markdown(content,
                                        output_format='html5',
                                        extensions=['extra'])
            handler.send(mail_address, header, content)
    except Exception as e:
        mail_exception = e

    wechat_exception = None
    try:
        if wechat == 'yes':
            handler = new_handler('wechat')
            wechat_info = Notification.query.filter_by(type='wechat').first()
            key = wechat_info.number
            handler.send(key, header, content)
    except Exception as e:
        wechat_exception = e

    if mail_exception is not None and wechat_exception is not None:
        raise Exception('Mail Exception: {}, Wechat Exception: {}'.format(
            repr(mail_exception), repr(wechat_exception)))

    if mail_exception is not None:
        if wechat == 'yes':
            raise Exception('其中一种通知方式失败, Mail Exception: {}'.format(
                repr(mail_exception)))
        else:
            raise Exception('Mail Exception: {}'.format(repr(mail_exception)))

    if wechat_exception is not None:
        if mail == 'yes':
            raise Exception('其中一种通知方式失败, Wechat Exception: {}'.format(
                repr(wechat_exception)))
        else:
            raise Exception('Wechat Exception: {}'.format(
                repr(wechat_exception)))
コード例 #3
0
ファイル: scheduler.py プロジェクト: txwh1/WebMonitor
def send_message(content, header, mail, wechat):
    from app.main.notification.notification_handler import new_handler

    try:
        if mail == 'yes':
            handler = new_handler('mail')
            mail_info = Notification.query.filter_by(type='mail').first()
            mail_address = mail_info.number
            content = markdown.markdown(content,
                                        output_format='html5',
                                        extensions=['extra'])
            handler.send(mail_address, header, content)

        if wechat == 'yes':
            handler = new_handler('wechat')
            wechat_info = Notification.query.filter_by(type='wechat').first()
            key = wechat_info.number
            handler.send(key, header, content)
    except Exception as e:
        raise e