Exemplo n.º 1
0
    def add(self, name, obj, expire_time, lead_times):
        try:
            _id = "_".join([obj.__class__.__name__, str(obj.id)])

            if not isinstance(lead_times, list):
                lead_times = [lead_times]

            content = "神盾局OPS系统:前方英雄【%s 编号:%s】即将在【%s】过期,请及时充能!!" % (
                name, str(obj.id), expire_time.strftime("%Y-%m-%d")
            )

            for lead_time in lead_times:
                date = expire_time - lead_time

                BaseSms.send(self,
                             [u.mobile for u in Group.get_users(DEFAULT_GROUP.SMS.ALERT)],
                             content, date=date, _id="_".join([_id, str(lead_time.days)]))

                BaseMail.send(self,
                              [app.config["MAIL_ALERT"]],
                              content,
                              "",
                              "mail.alert.tpl.html",
                              date=date,
                              _id="_".join([_id, str(lead_time.days)]))

        except Exception, e:
            traceback.print_exc()
            log.exception(e)
            raise ExceptionEx("添加邮件或短信提示失败!")
Exemplo n.º 2
0
    def add(self, name, obj, expire_time, lead_times):
        try:
            _id = "_".join([obj.__class__.__name__, str(obj.id)])

            if not isinstance(lead_times, list):
                lead_times = [lead_times]

            content = "神盾局OPS系统:前方英雄【%s 编号:%s】即将在【%s】过期,请及时充能!!" % (
                name, str(obj.id), expire_time.strftime("%Y-%m-%d"))

            for lead_time in lead_times:
                date = expire_time - lead_time

                BaseSms.send(self, [
                    u.mobile for u in Group.get_users(DEFAULT_GROUP.SMS.ALERT)
                ],
                             content,
                             date=date,
                             _id="_".join([_id, str(lead_time.days)]))

                BaseMail.send(self, [app.config["MAIL_ALERT"]],
                              content,
                              "",
                              "mail.alert.tpl.html",
                              date=date,
                              _id="_".join([_id, str(lead_time.days)]))

        except Exception, e:
            traceback.print_exc()
            log.exception(e)
            raise ExceptionEx("添加邮件或短信提示失败!")
Exemplo n.º 3
0
    def delete(self, obj, lead_times):
        try:
            for lead_time in lead_times:
                try:
                    _id = "_".join([obj.__class__.__name__, str(obj.id), str(lead_time.days)])
                    BaseSms.remove(self, _id)
                    BaseMail.remove(self, _id)
                except JobLookupError, e:
                    traceback.print_exc()
                    log.exception(e)
                    continue

        except Exception, e:
            traceback.print_exc()
            log.exception(e)
            raise ExceptionEx("删除邮件或短信提示失败!")
Exemplo n.º 4
0
    def delete(self, obj, lead_times):
        try:
            for lead_time in lead_times:
                try:
                    _id = "_".join([
                        obj.__class__.__name__,
                        str(obj.id),
                        str(lead_time.days)
                    ])
                    BaseSms.remove(self, _id)
                    BaseMail.remove(self, _id)
                except JobLookupError, e:
                    traceback.print_exc()
                    log.exception(e)
                    continue

        except Exception, e:
            traceback.print_exc()
            log.exception(e)
            raise ExceptionEx("删除邮件或短信提示失败!")
Exemplo n.º 5
0
    def delete(self, obj, lead_times):
        try:
            for lead_time in lead_times:
                try:
                    _id = "_".join([
                        obj.__class__.__name__,
                        str(obj.id),
                        str(lead_time.days)
                    ])
                    BaseSms.remove(self, _id)
                    BaseMail.remove(self, _id)
                except JobLookupError, e:
                    traceback.print_exc()
                    log.exception(e)
                    continue

        except Exception, e:
            traceback.print_exc()
            log.exception(e)
            raise ExceptionEx("删除邮件或短信提示失败!")


if __name__ == "__main__":
    from datetime import datetime
    print BaseMail().send(app.config["MAIL_ALERT"],
                          "xxxx",
                          "",
                          "mail.alert.tpl.html",
                          date=datetime.now(),
                          _id="xawdg")