def caseView(code, From):
                    try:
                        req = requests.get(DETAIL_URL.format(code), headers=BHEADERS,
                            cookies=AutoReportGlobals.GreenCookie, timeout=60)
                        if req.text.find("版权所有") > 0:  # 需要重新登录
                            self.logger.warn("需要重新登录")
                            login()  # 重新登录
                            self.logger.debug("登录成功")
                            req = requests.get(DETAIL_URL.format(code), headers=BHEADERS,
                                cookies=AutoReportGlobals.GreenCookie, timeout=60)
#                             print(req, req.text.find("版权所有"))
                            if req.text.find("版权所有") > 0:  # 需要重新登录
                                return self.logger.warn("又需要重新登录,放弃此操作")
                        if not hasattr(self, "CaseStyle"):  # ../../datas/jobs/EmailMonitorJob/
                            self.CaseStyle = open("jobs/EmailMonitorJob/CaseStyle.css", "rb").read().decode() + "</style>"
                        html = req.text.replace('class="menu_title"', 'class="menu_title" style="display: none;"').replace("</style>", self.CaseStyle)  # 替换样式表
                        self.logger.debug("email len: %s" % len(html))
                        # 发送邮件
                        message = MIMEMultipart()
                        subject = "工单查看-%s" % code
                        message.attach(MIMEText(html, _subtype="html", _charset="gb2312"))
                        sendEmail(subject, message, From)
                        self.logger.debug("工单查看邮件已发送")
                    except Exception as e:
                        self.logger.error(str(e))
 def errorReply(eid, From):
     # 发送邮件
     try:
         message = MIMEMultipart()
         subject = "日报控制-错误"
         message.attach(MIMEText("未找到该email id: {0}".format(eid)))
         sendEmail(subject, message, From)
         del AutoReportGlobals.EmailIds[eid]  # 删除
     except Exception as e:
         self.logger.error(str(e))
 def controlReply(subject, dataDir, peoples, whichs, From):
     # 发送彩信和邮件
     try:
         result = sendMms(subject, dataDir, peoples, whichs, "")
         message = MIMEMultipart()
         subject = "日报控制-" + ("成功" if result == 1 else "失败")
         message.attach(MIMEText(str(result)))
         sendEmail(subject, message, From)
         del AutoReportGlobals.EmailIds[eid]  # 删除
     except Exception as e:
         self.logger.error(str(e))
Esempio n. 4
0
 def controlReply(subject, content, peoples, From):
     # 发送文本彩信
     try:
         result = sendTextMms(subject, content, peoples)
         message = MIMEMultipart()
         subject = "控制-" + ("成功" if result == 1 else "失败")
         message.attach(MIMEText(str(result)))
         sendEmail(subject, message, From)
         del AutoReportGlobals.EmailIds[eid]  # 删除
     except Exception as e:
         self.logger.error(str(e))
     del AutoReportGlobals.EmailIds[eid]  # 删除
Esempio n. 5
0
    def _sendEmail(self, eid, subject, dataDir, preSend, formalSend, typ=0):
        peoples = formalSend if typ else preSend  # 如果采用邮箱正式发送
        subject = subject + datetime.now().strftime(" - %Y%m%d %H:%M:%S")
        subject = subject if typ else subject + " - 预览"
        message = MIMEMultipart()
        message["Subject"] = Header(subject, "gb2312")  # 邮件主题
        # 邮件正文
        imglist = os.listdir(dataDir)  # 遍历图片
        imglist.sort(key=lambda x: int(x[:-4]))  # 排序
        content = MIMEText(MailTemplate.render(
            subject=subject, imglist=imglist, eid=eid
        ), _subtype="html", _charset="gb2312")
        message.attach(content)
        # 添加图片附件
        for ipath in imglist:
            with open(os.path.join(dataDir, ipath), "rb") as fp:
                img = MIMEImage(fp.read())
                img.add_header("Content-ID", ipath)
                message.attach(img)
        sendEmail(subject, message, peoples)
        # 发送微信图片
#         if not AutoReportGlobals.WeixinBot: return
#         for ipath in imglist:
#             AutoReportGlobals.WeixinBot.sendImage(os.path.join(dataDir, ipath))
        # 调整为多进程网页请求
        _json = {
            "type": "image",
            "data": [os.path.abspath(os.path.join(dataDir, ipath)) for ipath in imglist]
        }
#         print(_json.get("data"))
        try:
            req = requests.post(
                "http://127.0.0.1:%s/api/wechat/send" % self.port, json=_json)
#             print(req.text)
            if req.json().get("code") != 1:
                return self.logger.error("微信群消息发送失败")
            self.logger.debug("微信群图片发送完毕")
            _json = {
                "type": "text",
                "data": """任务ID:%s\r\n
说明:回复命令格式:\r\n
日报发送,%s,1,2,3,4,5,6,7,8,9 表示只发送指定序号的图片\r\n
日报发送,%s 表示全部发送""" % (eid, eid, eid)
            }
            req = requests.post(
                "http://127.0.0.1:%s/api/wechat/send" % self.port, json=_json)
#             print(req.text)
            if req.json().get("code") != 1:
                return self.logger.error("微信群消息发送失败")
            self.logger.debug("微信群文字消息发送完毕")
        except Exception as e:
            self.logger.error(str(e))
Esempio n. 6
0
    def _sendEmail(self, eid, subject, content, preSend, formalSend, typ=0):
        peoples = formalSend if typ else preSend  # 如果采用邮箱正式发送
        subject = subject + datetime.now().strftime(" - %Y%m%d %H:%M:%S")
        subject = subject if typ else subject + " - 预览"
        message = MIMEMultipart()
        message["Subject"] = Header(subject, "gb2312")  # 邮件主题
        # 邮件正文
        msg = MIMEText(MailTemplate.render(
            subject=subject, content=content, eid=eid
        ), _subtype="html", _charset="gb2312")
        message.attach(msg)
#         content = MIMEText(content + "\n\n控制命令:   T%s" % eid, _charset="gb2312")
#         message.attach(content)
        sendEmail(subject, message, peoples)
Esempio n. 7
0
 def _sendEmail(self, subject, file, preSend):
     peoples = preSend  # 如果采用邮箱正式发送
     subject = subject + datetime.now().strftime(" - %Y%m%d %H:%M:%S")
     message = MIMEMultipart()
     message["Subject"] = Header(subject, "gb2312")  # 邮件主题
     # 邮件正文
     content = MIMEText(MailTemplate, _charset="gb2312")
     message.attach(content)
     # 添加附件
     xlsfile = MIMEBase("application", "octet-stream")
     xlsfile.set_payload(open(file, "rb").read())
     xlsfile.add_header("Content-Disposition",
                        "attachment",
                        filename=os.path.basename(file))
     encode_base64(xlsfile)
     message.attach(xlsfile)
     sendEmail(subject, message, peoples)
    def start(self):
        self.getLogin()
        # 登录成功
        # 监控数据
        self.logger.debug("monitor start")
        req = requests.get(COUNT_URL,
                           headers=HEADERS,
                           cookies=self.cookies,
                           timeout=60)
        if req.text.find("版权所有") > 0:  # 需要重新登录
            self.logger.debug("需要重新登录")
            self.getLogin()

        # 当前数量
        count = re.findall(ReCount, req.text)
        self.logger.debug("当前需处理的记录数为:%s" % count)

        # 有序字典
        orders = OrderedDict()

        # 普通工单
        gorders = self.getItem("普通工单", ReGeneralWorkOrder, req.text)
        # print("普通工单", gorders)
        self.logger.debug("普通工单:%s" % gorders)
        orders["普通工单"] = gorders

        # 危机工单
        corders = self.getItem("危机工单", ReCrisisWorkOrder, req.text)
        # print("危机工单", corders)
        self.logger.debug("危机工单:%s" % corders)
        orders["危机工单"] = corders

        # 升级工单
        uorders = self.getItem("升级工单", ReUpgradeWorkOrder, req.text)
        # print("升级工单", uorders)
        self.logger.debug("升级工单:%s" % uorders)
        orders["升级工单"] = uorders

        # 已超时工单
        oorders = self.getItem("已超时工单", ReOvertimeWorkOrder, req.text)
        # print("已超时工单", oorders)
        self.logger.debug("已超时工单:%s" % oorders)
        orders["已超时工单"] = oorders

        # 预超时工单
        porders = self.getItem("预超时工单", RePretimeWorkOrder, req.text)
        # print("预超时工单", porders)
        self.logger.debug("预超时工单:%s" % porders)
        orders["预超时工单"] = porders

        # 获取催单提醒
        urges = ""
        req = requests.get(REMIND_URL,
                           headers=RHEADERS,
                           cookies=self.cookies,
                           timeout=60)
        if len(req.text) < 500:
            urges = req.text
        self.logger.debug("工单催单:%s" % urges)

        if all(
            (not gorders, not corders, not uorders, not oorders, not porders)):
            # print("当前没有需要处理的工单")
            return self.logger.info("当前没有需要处理的工单")

        title = "{0} 绿网投诉统计".format(
            datetime.now().strftime("%Y/%m/%d %H:%M:%S"))
        text = MailTemplate.render(title=title,
                                   count=count[0] if count else "0",
                                   orders=orders,
                                   urges=urges.replace("<br/>", "").replace(
                                       "<br>",
                                       "").replace("<br/ >", "").replace(
                                           "\r\n",
                                           "<br/ >").replace("\n", "<br/ >"))
        # print(text)
        message = MIMEText(text, _subtype="html", _charset="gb2312")
        self.logger.debug(str(sendEmail(title, message, self.preSend)))
        self.logger.info("本时段绿网统计发送完毕")
        #         if not AutoReportGlobals.WeixinBot:
        #             return
        '''