From fc452019985d004f993ce424d267b7e5450ef52c Mon Sep 17 00:00:00 2001 From: ngfchl Date: Thu, 5 Jan 2023 09:31:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E7=B2=BE=E7=AE=80=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=8C=E5=87=8F=E5=B0=91html=E8=BE=93?= =?UTF-8?q?=E5=87=BA=202.=20=E4=BC=98=E5=8C=96unit3D=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E7=AB=99=E7=82=B9=E9=82=AE=E4=BB=B6=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt.json | 12 ++++----- pt_site/UtilityTool.py | 60 ++++++++++++++++++++++++++++-------------- pt_site/admin.py | 1 + pt_site_site.json | 12 ++++----- 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/pt.json b/pt.json index a92364c..7cb86a1 100644 --- a/pt.json +++ b/pt.json @@ -6634,7 +6634,7 @@ "pk": 92, "fields": { "created_at": "2022-12-25T17:54:44.854", - "updated_at": "2023-01-04T21:44:06.583", + "updated_at": "2023-01-05T09:21:51.841", "url": "https://monikadesign.uk/", "name": "莫妮卡", "nickname": "monika", @@ -6652,7 +6652,7 @@ "page_download": "download.php?id={}", "page_user": "users/{}", "page_search": "torrents.php?search={}", - "page_message": "messages.php", + "page_message": "mail/inbox", "page_hr": "myhr.php?hrtype=1&userid={}", "page_leeching": "getusertorrentlistajax.php?userid={}&type=leeching", "page_uploaded": "getusertorrentlistajax.php?userid={}&type=uploaded", @@ -7144,7 +7144,7 @@ "pk": 98, "fields": { "created_at": "2022-12-26T14:03:05.511", - "updated_at": "2023-01-04T21:44:06.609", + "updated_at": "2023-01-05T09:22:10.186", "url": "https://pt.hdpost.top/", "name": "普斯特", "nickname": "hdpost", @@ -7162,7 +7162,7 @@ "page_download": "download.php?id={}", "page_user": "users/{}", "page_search": "torrents.php?search={}", - "page_message": "messages.php", + "page_message": "mail/inbox", "page_hr": "myhr.php?hrtype=1&userid={}", "page_leeching": "getusertorrentlistajax.php?userid={}&type=leeching", "page_uploaded": "getusertorrentlistajax.php?userid={}&type=uploaded", @@ -7399,7 +7399,7 @@ "pk": 101, "fields": { "created_at": "2022-12-27T12:56:12.440", - "updated_at": "2023-01-04T21:44:06.623", + "updated_at": "2023-01-05T09:21:29.567", "url": "https://reelflix.xyz/", "name": "Reelflix", "nickname": "reelflix", @@ -7417,7 +7417,7 @@ "page_download": "download.php?id={}", "page_user": "users/{}", "page_search": "torrents.php?search={}", - "page_message": "messages.php", + "page_message": "mail/inbox", "page_hr": "myhr.php?hrtype=1&userid={}", "page_leeching": "getusertorrentlistajax.php?userid={}&type=leeching", "page_uploaded": "getusertorrentlistajax.php?userid={}&type=uploaded", diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index 903024d..cd4cbea 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -544,9 +544,10 @@ class PtSpider: return CommonResponse.success( msg='你还需要继续努力哦!此次签到,你获得了魔力奖励:{}'.format(sign_res) ) - except: + except Exception as e: + logger.info(traceback.format_exc(3)) return CommonResponse.error( - msg=f'签到失败!{sign_res}' + msg=f'签到失败!{sign_res}: {e}' ) def sign_in_hd4fans(self, my_site: MySite): @@ -870,10 +871,11 @@ class PtSpider: if datetime.now().hour < 9: # U2/52PT 每天九点前不签到 queryset = [my_site for my_site in queryset if my_site.site.url not in [ - 'https://u2.dmhy.org/', 'https://52pt.site/' + 'https://u2.dmhy.org/', + # 'https://52pt.site/' ] and my_site.signin_set.filter(created_at__date__gte=datetime.today()).count() <= 0 and my_site.cookie] - message = '> 站点:`U2`以及`52PT` 早上九点之前不执行签到任务哦! \n\n' + message = '> 站点:`U2` 早上九点之前不执行签到任务哦! \n\n' logger.info(message) message_list = message + message_list else: @@ -1144,7 +1146,7 @@ class PtSpider: ) if 'btschool' in site.url: # logger.info(res.status_code) - logger.info('学校签到:{}'.format(res.text.encode('utf-8'))) + logger.info('学校签到:{}'.format(res.text)) text = self.parse(res, '//script/text()') logger.info('解析签到返回信息:{}'.format(text)) if len(text) > 0: @@ -1164,7 +1166,7 @@ class PtSpider: return CommonResponse.error(msg='签到失败!请求响应码:{}'.format(res.status_code)) if res.status_code == 200: status = converter.convert(res.text.encode('utf8')) - logger.info(status) + # logger.info(status) # status = ''.join(self.parse(res, '//a[contains(@href,{})]/text()'.format(site.page_sign_in))) # 检查是否签到成功! # if '签到得魔力' in converter.convert(status): @@ -1191,10 +1193,10 @@ class PtSpider: '//p[contains(text(),"本次签到获得魅力")]/preceding-sibling::h1[1]/span/text()' ) content_parse = self.parse(res, '//p[contains(text(),"本次签到获得魅力")]/text()') + logger.info(f'签到信息标题:{content_parse}') + logger.info(f'签到信息:{content_parse}') title = ''.join(title_parse).strip() - # logger.info(content_parse) content = ''.join(content_parse).strip().replace('\n', '') - # logger.info(content) message = title + ',' + content logger.info(f'{my_site} 签到返回信息:{message}') if len(message) <= 1: @@ -1577,6 +1579,9 @@ class PtSpider: 'https://pt.btschool.club/', 'https://pt.keepfrds.com/', 'https://pterclub.com/', + 'https://monikadesign.uk/', + 'https://pt.hdpost.top/', + 'https://reelflix.xyz/', ]: logger.info(site.url) details_html = etree.HTML(converter.convert(user_detail_res.text)) @@ -1649,7 +1654,7 @@ class PtSpider: else: seeding_detail_res = self.send_request(my_site=my_site, url=seeding_detail_url, delay=25) - logger.info('做种信息:{}'.format(seeding_detail_res.text)) + logger.info('做种信息:{}'.format(seeding_detail_res)) # leeching_detail_res = self.send_request(my_site=my_site, url=leeching_detail_url, timeout=25) if seeding_detail_res.status_code != 200: return CommonResponse.error( @@ -1918,8 +1923,8 @@ class PtSpider: elif site.url in [ 'https://monikadesign.uk/', 'https://pt.hdpost.top/', - 'https://pterclub.com/', 'https://reelflix.xyz/', + 'https://pterclub.com/', 'https://hd-torrents.org/', 'https://filelist.io/', 'https://www.pttime.org/', @@ -2160,23 +2165,38 @@ class PtSpider: else: ratio = round(int(uploaded) / int(downloaded), 3) if ratio and ratio != 'inf' and float(ratio) <= 1: - message = f'# {site.name} 站点分享率告警:{ratio} \n' - self.send_text(title=message, message=message) + title = f'{site.name} 站点分享率告警:{ratio}' + message = f'# {title} \n' + self.send_text(title=title, message=message) # 检查邮件 - mail_str = ''.join(details_html.xpath(site.mailbox_rule)) - 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 + mail_check = len(details_html.xpath(site.mailbox_rule)) + notice_check = len(details_html.xpath(site.notice_rule)) + if mail_check > 0 or notice_check > 0: + if site.url in [ + 'https://monikadesign.uk/', + 'https://pt.hdpost.top/', + 'https://reelflix.xyz/', + ]: + mail_count = mail_check + notice_str = ''.join(details_html.xpath(site.notice_rule)) + notice_count = 0 + else: + mail_str = ''.join(details_html.xpath(site.mailbox_rule)) + notice_str = ''.join(details_html.xpath(site.notice_rule)) + 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 my_site.mail = mail_count + notice_count if mail_count > 0: message_res = self.send_request(my_site, url=site.url + site.page_message) + logger.info(message_res.text) mail_list = self.parse(message_res, site.message_title) + mail_list = [mail.strip() for mail in mail_list] + logger.info(mail_list) mail = " \n\n> ".join(mail_list) logger.info(mail) - title = f'{site.name} 有{mail_count + notice_count}条新短消息,请注意及时查收!' + title = f'{site.name} 有{len(mail_list) + notice_count}条新短消息,请注意及时查收!' # 测试发送网站消息原内容 message = f'{notice_str} \n> {mail}' self.send_text(title=title, message=message) diff --git a/pt_site/admin.py b/pt_site/admin.py index c6c69d5..03393bf 100644 --- a/pt_site/admin.py +++ b/pt_site/admin.py @@ -121,6 +121,7 @@ class SiteAdmin(admin.ModelAdmin): # instead of ModelAdmin 'page_user', 'page_control_panel', 'page_search', + 'page_message', 'page_leeching', 'page_uploaded', 'page_seeding', diff --git a/pt_site_site.json b/pt_site_site.json index bc2e61f..212758b 100644 --- a/pt_site_site.json +++ b/pt_site_site.json @@ -6398,7 +6398,7 @@ { "id": 92, "created_at": "2022-12-25 17:54:44.854475", - "updated_at": "2023-01-04 21:44:06.583588", + "updated_at": "2023-01-05 09:21:51.841578", "name": "莫妮卡", "url": "https://monikadesign.uk/", "logo": "https://monikadesign.uk/favicon.ico", @@ -6475,7 +6475,7 @@ "search_params": "{\"免费\":\"spstate=2\",\"2X\":\"spstate=3\",\"2X免费\":\"spstate=4\",\"50%\":\"spstate=5\",\"2X 50%\":\"spstate=6\",}", "full_site_free": "//span[contains(text(),\"全站免费\")]/following-sibling::div/span/text()", "message_title": "//td/span[@class=\"label label-danger\"]/parent::td/preceding-sibling::td[@class=\"col-sm-5\"]/a/text()", - "page_message": "messages.php" + "page_message": "mail/inbox" }, { "id": 93, @@ -6890,7 +6890,7 @@ { "id": 98, "created_at": "2022-12-26 14:03:05.511105", - "updated_at": "2023-01-04 21:44:06.609557", + "updated_at": "2023-01-05 09:22:10.186390", "name": "普斯特", "url": "https://pt.hdpost.top/", "logo": "https://pt.hdpost.top/favicon.ico", @@ -6967,7 +6967,7 @@ "search_params": "{\"免费\":\"spstate=2\",\"2X\":\"spstate=3\",\"2X免费\":\"spstate=4\",\"50%\":\"spstate=5\",\"2X 50%\":\"spstate=6\",}", "full_site_free": "//span[contains(text(),\"全站免费\")]/following-sibling::div/span/text()", "message_title": "//td/span[@class=\"label label-danger\"]/parent::td/preceding-sibling::td[@class=\"col-sm-5\"]/a/text()", - "page_message": "messages.php" + "page_message": "mail/inbox" }, { "id": 99, @@ -7136,7 +7136,7 @@ { "id": 101, "created_at": "2022-12-27 12:56:12.440343", - "updated_at": "2023-01-04 21:44:06.623597", + "updated_at": "2023-01-05 09:21:29.567305", "name": "Reelflix", "url": "https://reelflix.xyz/", "logo": "https://reelflix.xyz/favicon.ico", @@ -7213,7 +7213,7 @@ "search_params": "{\"免费\":\"spstate=2\",\"2X\":\"spstate=3\",\"2X免费\":\"spstate=4\",\"50%\":\"spstate=5\",\"2X 50%\":\"spstate=6\",}", "full_site_free": "//span[contains(text(),\"全站免费\")]/following-sibling::div/span/text()", "message_title": "//td/i[@class=\"fal fa-cross text-red\"]/parent::td/preceding-sibling::td/a/text()", - "page_message": "messages.php" + "page_message": "mail/inbox" }, { "id": 102,