From cc38b6f7ec6c6617371f7584cc2d2002af52468f Mon Sep 17 00:00:00 2001 From: ngfchl Date: Mon, 5 Sep 2022 20:40:25 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=96=B0=E4=BF=A1=E6=81=AF=E6=95=B0=E9=87=8F=E4=BC=9A=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E6=97=A2=E5=BE=80=E6=B6=88=E6=81=AF=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E7=9A=84bug=202.=20=E5=90=8C=E6=97=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=85=AC=E5=91=8A=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_site/UtilityTool.py | 33 +++++++++++-------- ...ite_notice_rule_alter_site_mailbox_rule.py | 33 +++++++++++++++++++ pt_site/models.py | 6 +++- 3 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 pt_site/migrations/0006_site_notice_rule_alter_site_mailbox_rule.py diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index 8be2334..14d0e9c 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -883,14 +883,6 @@ class PtSpider: msg=StatusCodeEnum.WEB_CONNECT_ERR.errmsg + '请检查网站访问是否正常?' ) # seed = len(seed_vol_list) - ratio = ''.join( - details_html.xpath(site.ratio_rule) - ).replace(',', '').replace('无限', 'inf').replace('∞', 'inf').replace('---', 'inf').strip(']:').strip() - # 分享率告警通知 - print('ratio', ratio) - if ratio != 'inf' and float(ratio) <= 1: - message = '# ' + site.name + ' 站点分享率告警:' + str(ratio) + ' \n' - self.send_text(message) downloaded = ''.join( details_html.xpath(site.downloaded_rule) @@ -982,11 +974,26 @@ class PtSpider: # print('上传数:', seed) # print('下载数:', leech) try: + ratio = ''.join( + details_html.xpath(site.ratio_rule) + ).replace(',', '').replace('无限', 'inf').replace('∞', 'inf').replace('---', 'inf').strip(']:').strip() + # 分享率告警通知 + print('ratio', ratio) + if ratio != 'inf' and float(ratio) <= 1: + message = '# ' + site.name + ' 站点分享率告警:' + str(ratio) + ' \n' + self.send_text(message) + # 检查邮件 mail_str = ''.join(details_html.xpath(site.mailbox_rule)) - mail_count = re.findall('\d', mail_str)[-1] - if int(mail_count) > 0: - template = '### {} 有{}条新短消息,请注意及时查收!' - self.send_text(template.format(site.name, mail_count)) + notice_str = ''.join(details_html.xpath(site.notice_rule)) + if mail_str or notice_str: + mail_count = re.sub(u"([^\u0030-\u0039])", "", mail_str) + notice_count = re.sub(u"([^\u0030-\u0039])", "", notice_str) + mail_count = int(mail_count) if mail_count else 0 + notice_count = int(notice_count) if notice_count else 0 + if mail_count + notice_count > 0: + template = '### {} 有{}条新短消息,请注意及时查收!' + self.send_text(template.format(site.name, mail_count + notice_count)) + res_sp_hour = self.get_hour_sp(my_site=my_site) if res_sp_hour.code != StatusCodeEnum.OK.code: logging.error(my_site.site.name + res_sp_hour.msg) @@ -1012,7 +1019,7 @@ class PtSpider: except Exception as e: message = my_site.site.name + '解析个人主页信息:失败!原因:' + str(e) logging.error(message) - # raise + raise self.send_text(site.name + '解析个人主页信息:失败!原因:' + str(e)) return CommonResponse.error(msg=message) diff --git a/pt_site/migrations/0006_site_notice_rule_alter_site_mailbox_rule.py b/pt_site/migrations/0006_site_notice_rule_alter_site_mailbox_rule.py new file mode 100644 index 0000000..4b3aab2 --- /dev/null +++ b/pt_site/migrations/0006_site_notice_rule_alter_site_mailbox_rule.py @@ -0,0 +1,33 @@ +# Generated by Django 4.1 on 2022-09-05 20:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("pt_site", "0005_alter_torrentinfo_hr"), + ] + + operations = [ + migrations.AddField( + model_name="site", + name="notice_rule", + field=models.CharField( + default='//a[@href="index.php"]/font/text()[1]', + help_text="获取新公告", + max_length=128, + verbose_name="公告规则", + ), + ), + migrations.AlterField( + model_name="site", + name="mailbox_rule", + field=models.CharField( + default='//a[@href="messages.php"]/font/text()', + help_text="获取新邮件", + max_length=128, + verbose_name="邮件规则", + ), + ), + ] diff --git a/pt_site/models.py b/pt_site/models.py index f6a8f9f..42e2725 100644 --- a/pt_site/models.py +++ b/pt_site/models.py @@ -209,9 +209,13 @@ class Site(BaseEntity): help_text='需对数据做处理', max_length=128) mailbox_rule = models.CharField(verbose_name='邮件规则', - default='//a[@href="messages.php"]/following-sibling::text()[1]', + default='//a[@href="messages.php"]/font/text()', help_text='获取新邮件', max_length=128) + notice_rule = models.CharField(verbose_name='公告规则', + default='//a[@href="index.php"]/font/text()[1]', + help_text='获取新公告', + max_length=128) # HASH RULE hash_rule = models.CharField(verbose_name='种子HASH', default='//tr[11]//td[@class="no_border_wide"][2]/text()',