コード例 #1
0
 async def do_post(self, data: dict) -> HTTPResponse:
     text = f"{data['text']}\n\n<strong>{data['user']}</strong>\t{data['email']}\t{data['site']}"
     post_data = [('chat_id', FEEDBACK_CHAT_ID), ('text', text), ('parse_mode', 'html')]
     request = HTTPRequest(url=URL, method='POST', body=urlencode(post_data))
     http_client = AsyncHTTPClient()
     try:
         response = await http_client.fetch(request)
     except Exception as e:
         app_log.error(f"Error: {e}")
     else:
         result_json = json_decode(response.body)
         if response.code == 200:
             app_log.info(
                 f"Data send to chat {result_json['result']['chat']['title']} with reason: {response.reason}"
             )
         else:
             app_log.log(f"Data do NOT send to destination with reason: {response.reason}")
         return response
コード例 #2
0
ファイル: hd_mail.py プロジェクト: FYPYTHON/notes
    def sendEmail(self, msg):
        """
        邮件通知
        :param str: email content
        :return:
        """
        try:
            loginname = self.get_argument("loginname", None)
            user = get_user_info_app(self, loginname)
            if user is None:
                weblog.error(u"用户邮箱获取失败:{}".format(user))
                return False
            else:
                receiver = user.email
            if "email" in self.localVariable.keys():
                sender = self.localVariable.get("email")
                subject = '恭喜,您已订票成功'
                username = self.localVariable.get("email")
                password = self.localVariable.get("emailpwd")
                host = "smtp.126.com"
                s = "{0}".format(msg)

                msg = MIMEText(s, 'plain', 'utf-8')  # 中文需参数‘utf-8’,单字节字符不需要
                msg['Subject'] = Header(subject, 'utf-8')
                msg['From'] = sender
                msg['To'] = receiver
                # print(sender, receiver, username, password)
                weblog.log("send:{}  to receiver:{}".format(sender, receiver))
                try:
                    smtp = smtplib.SMTP_SSL(host)
                    smtp.connect(host)
                except socket.error:
                    smtp = smtplib.SMTP()
                    smtp.connect(host)
                smtp.connect(host)
                smtp.login(username, password)
                smtp.sendmail(sender, receiver.split(","), msg.as_string())
                smtp.quit()
                weblog.info(u"邮件已通知, 请查收")
                return True
        except Exception as e:
            weblog.error(u"邮件配置有误{}".format(e))
            return False
コード例 #3
0
def log_fds(mes=''):
    if options.debug:
        app_log.log(logging.DEBUG, 'fds (%s): %s' % (mes, fds()))
コード例 #4
0
def log_mem(mes=''):
    if options.debug:
        all_objects = muppy.get_objects()
        sum1 = summary.summarize(all_objects)
        app_log.log(logging.DEBUG, 'mem (%s): %d' % (mes, len(all_objects)))
        summary.print_(sum1)
コード例 #5
0
def app_log_process(message, level=logging.INFO):
    app_log.log(level, '(%s) %s' % (get_process_name(), message))