From 00c102b4cb6a2b573266ecde7ac1d64092a3d1c7 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Fri, 23 Dec 2022 17:34:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9A=84=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E7=8E=87=E6=97=A0=E6=B3=95=E8=BD=AC=E4=B8=BA=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=87=AA=E8=A1=8C=E8=AE=A1=E7=AE=97=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_site/UtilityTool.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index 4d36444..afc002a 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -1820,8 +1820,16 @@ class PtSpider: .replace('\xa0', '').replace('.', '').strip() # 分享率告警通知 logger.info('ratio:{}'.format(ratio)) + try: + # 获取的分享率无法转为数字时,自行计算分享率 + ratio = float(ratio) + except Exception: + if int(downloaded) == 0: + ratio = 'inf' + else: + ratio = round(int(uploaded) / int(downloaded), 3) if ratio and ratio != 'inf' and float(ratio) <= 1: - message = '# ' + site.name + ' 站点分享率告警:' + str(ratio) + ' \n' + message = f'# {site.name} 站点分享率告警:{ratio} \n' self.send_text(message) # 检查邮件 mail_str = ''.join(details_html.xpath(site.mailbox_rule))